Skip to content
Prev 179940 / 398503 Next

R Error, very odd....

At 12:37 AM -0700 5/11/09, Katie2009 wrote:
Well, you can look at the data to find out. Either just print it, or 
perhaps use simple exploration techniques, such as
   unique( column)
   table(column)
   summary(column)
compare before and after converting to numeric

In general, changing a factor to numeric can change the data relative 
to what you might think the data actually is.  Here is an example:
[1] -1  0  1
[1] -1 0  1
Levels: -1 0 1
[1] 1 2 3

tmp3 is  clearly not the same as tmp1.
[1] -1  0  1


Evidently, R is creating a factor from a column that you think is 
numeric. Your job is to find out why. I would guess that you have, 
somewhere in the column, an entry that isn't a number. Perhaps a 
typographical error in the spreadsheet column. The effect of 
inputting as absolute values vs with negative numbers should give a 
clue to that.

Try
    tmp <-  as.numeric(format( column ))
    any(is.na(tmp))
and if that is TRUE, then
    column[is.na(tmp)]

-Don