0

i have a variable that contains numbers as below:

[1] 76.19047619  71.42857143  70.37037037  78.72340426  94.54545455  86.53846154  80.58936579  57.77777778 
[9] 96.00000000  89.79591837  81.25000000  100.00000000 92.00000000  61.53846154  96.42857143  88.88888889 

when i bring this in R, they come as factors instead of numbers with the following message:

1577 Levels: #DIV/0! 0.00000000 0.05122951 0.05288207 0.06146281 0.13917884 0.26200873 0.26666667 ... 97.46376812

how can coerce them into numeric, i have tried as.integers and as.numeric but when i use that variable in computation, the results dont change. they are the same as when it is factors.

Thanks,

Alex P
  • 12,249
  • 5
  • 51
  • 70
jonestats
  • 349
  • 1
  • 3
  • 10
  • 1
    I'm guessing this is a duplicate but use `as.numeric(as.character(vect))` – Tyler Rinker Feb 19 '13 at 10:02
  • How do you read theses factors? using read.table for example? You can avoid the conversion if you specify types using colClasses... – agstudy Feb 19 '13 at 10:06
  • see [this answer](http://stackoverflow.com/a/14880892/1317221) it is your `#DIV/0!` causing things to be factors. using `read.table(x, stringsAsFactors=FALSE)` will stop the requirement for `as.character` but you should think about what you want to do with the `#DIV/0!` – user1317221_G Feb 19 '13 at 10:07
  • I just realized there was a division by zero generating the factors aand i have corrected that. – jonestats Feb 19 '13 at 10:55

0 Answers0