Skip to content
Prev 360890 / 398513 Next

changing factor to numbers without getting NAs

Hi,

First, how did you get the data into R? 

I am going to guess that you used ?read.table or ?read.csv, which by default, will convert character values into factors (see the 'as.is' argument).

Second, by default, the decimal character in R is a period ('.') and you appear to be importing European values where the decimal character is a comma (','). Thus, take note of the 'dec' argument in read.table/read.csv and modify that to dec = "," in your function call.

The NA values are the result of converting character values that cannot be coerced to numeric due to the commas:
[1] NA
Warning message:
NAs introduced by coercion
[1] 100.2

Regards,

Marc Schwartz