0

I have imported data which is reading in decimal numbers as factors. In the data some values are blank, and some are " - " for zero. I want to convert the field into a numeric, so i thought i should replace the "" with NA, and the " - " with "0" How can I do this? I prefer not to change the read.csv command, but instead be able to edit the vector.

data = read.csv(pathtofile)
x <- data$x
class(x)
x[""] <- NA
x[" - "] <- "0"
data$x <- x

x[" - "] <- "0" gives the warning In [<-.factor(*tmp*, " - ", value = "0") : invalid factor level, NA generated

Joe_Schmoe
  • 1,485
  • 3
  • 17
  • 19

0 Answers0