0

I’ve a data set (myData) that contains numerical, factor, and categorical variables. One of the variable, let’s call it $x$ is a factor and I’m trying to convert it to numeric. I came across this post, and this is what I used

### Convert myData$x from factor to numeric
myData$x <- as.numeric(levels(myData$x))[ myData$x]

it seems it works, but I got this warning message:

Warning message:
NAs introduced by coercion

Is that something I should be worried about? And how can I fix it?

Community
  • 1
  • 1
user9292
  • 1,125
  • 2
  • 12
  • 25
  • 3
    This means that there are non-numeric elements as levels which got coerced to `NA` by `as.numeric`. If you don't need the warnings, then use `?suppressWarnings`. I think this warning is a friendly reminder that your data column is not all `numeric` – akrun Mar 12 '15 at 15:11
  • as akrun said, it is nothing but read this post to understand it better http://stackoverflow.com/questions/14984989/how-to-avoid-warning-when-introducing-nas-by-coercion –  Mar 12 '15 at 15:16
  • Many thanks akurn and Nemo for the comments. This was very helpful to me! +1 – user9292 Mar 12 '15 at 15:18

0 Answers0