[R] R as.numeric()

Timothy Bates timothy.c.bates at gmail.com
Tue May 24 23:41:28 CEST 2011


On 24 May 2011, at 10:20 PM, Lutz Fischer wrote:
> n<-data.matrix(s);
> > s[1,2]
> [1] 30.94346629 # 3136 Levels: 0.026307482
> turned into:
> > n[1,2]
> [1] 3020

Dear Lutz, “3020” is the factor level associated with 30.94346629, in turn generated by importing with strings in the column

Try passing "na.strings = ’n/a’ “ into the read.xls function to avoid the problem

If not, then as.numeric(as.character(datafulloffactors) will work

as.numeric sees the factor levels: as.character forces as.numeric to see the “labels”

t



More information about the R-help mailing list