[R] factor level

Mike Miller mbmiller+l at gmail.com
Fri May 1 22:31:31 CEST 2009


Tell me how this works out for you.  I think R is seeing your "newXaxis" 
variable as a character variable because there is some non-numeric string 
in there, then it converts to factor.  Try setting stringsAsFactors=FALSE 
in the read.csv and see if it is then read as character.  If it is, try 
your command again:

mydata[,"newXaxis"]<-as.numeric(mydata[,"newXaxis"])

I don't know if this will work.  Just guessing.

Mike


On Fri, 1 May 2009, phoebe kong wrote:

> Hi All,
>
> I have problem about the factor features.
>
> I read in a .cvs file, a column which is supposed to be numeric, but it
> becomes factor level data after reading in.
>
> mydata[,"newXaxis"]
>  [1] 0           0.430010601 11.23198508 25.00940297 37.75338045
> 45.98289639
>  [7] 48.92328133 52.51142822 61.12359751 63.85832121 70.98927949
> 77.16550181
> [13] 97.73545713 113.6588007 118.6588007 129.9635717 151.8944844
> 178.7997437
> [19] 206.45806   248.5916724 309.2463405 373.436891  441.0136089
> 508.6003268
> [25] 586.8717683 670.5198381 760.8728108 854.0728565 948.6242311
> 1048.159042
> [31] 1150.177895 1257.016622 1262.016622 1273.775731 1295.941555
> 1331.142905
> [37] 1368.605796 1419.096727 1478.299769 1557.275945 1636.262122
> 1641.262122
> [43] 1642.586431
>
> 44 Levels: 0 0.430010601 10030.11259 10096.32795 10167.4591 ... newXaxis
>
> I tried to convert this column to numeric using command:
>
> mydata[,"newXaxis"]<-as.numeric(mydata[,"newXaxis"])
>
> However, it turned out a batch of integer numbers.
>
>> as.numeric(mydata[,"newXaxis"])
>  [1]   1   2  31 202 230 245 250 256 271 276 292 307 337  33  46  82 124
> 186
> [19] 191 201 213 228 240 253 266 280 305 317 332  15  39  64  65  71  80
> 87
> [37]  92  97 112
>
> Does anyone know how to remove the factor and remain the actual numeric
> data?
>
> Thanks a lot!
>
> Phoebe
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Please note that I am using a new email address.
My old email address @taxa.epi.umn.edu, will stop working
because that old computer is being retired.




More information about the R-help mailing list