I have code that comes with the dataset that I downloaded. This code should convert factor variables to numeric. When I run each line separately, it works fine, but if I try to select the entire section, I get the following error:
Error: unexpected input in ...
It gives me this error for each line of code, but then again, if I run each line individually, then it works fine. I have never encountered this before. What's happening?? Thanks!
Here is the code I'm trying to run:
library(prettyR) lbls <- sort(levels(DF$myVar)) lbls <- (sub("^\\([0-9]+\\) +(.+$)", "\\1", lbls)) DF$myVar <- as.numeric(sub("^\\(0*([0-9]+)\\).+$", "\\1", DF$myVar)) DF$myVar <- add.value.labels(DF$myVar, lbls)
And here is the error result:
> library(prettyR) "rror: unexpected input in "library(prettyR) > lbls <- sort(levels(DF$myVar)) "rror: unexpected input in "lbls <- sort(levels(DF$myVar)) > lbls <- (sub("^\\([0-9]+\\) +(.+$)", "\\1", lbls)) "rror: unexpected input in "lbls <- (sub("^\\([0-9]+\\) +(.+$)", "\\1", lbls)) > surv.df$myVar <- as.numeric(sub("^\\(0*([0-9]+)\\).+$", "\\1", DF$myVar)) "rror: unexpected input in "DF$myVar <- as.numeric(sub("^\\(0*([0-9]+)\\).+$", "\\1",DF$myVar)) > surv.df$BATTLEGROUND <- add.value.labels(DF$myVar, lbls) Error in add.value.labels(surv.df$myVar, lbls) : object 'lbls' not found
source share