[R] Factor to Numeric
Ivan Calandra
ivan.calandra at uni-hamburg.de
Wed May 26 09:43:40 CEST 2010
Hi,
What about:
as.numeric(as.character(data$State))
?
Ivan
Le 5/26/2010 09:32, Mohan L a écrit :
> Dear All,
>
> I have a data frame with State and 12 Months as column. I want to convert
> all the 12 month column from factor to numeric.
> any help will be greatly appreciated.
>
>> str(data)
>>
> 'data.frame': 33 obs. of 9 variables:
> $ State : Factor w/ 33 levels "Andaman and Nicobar Islands",..: 1 2 3 4
> 5 6 7 8 9 10 ...
> $ April : Factor w/ 21 levels "0","1","10","116",..: 2 16 1 1 9 20 1 1 2
> 21 ...
> $ August : Factor w/ 18 levels "0","1","10","125",..: 1 14 1 1 9 3 1 1 2
> 5 ...
> $ February : Factor w/ 19 levels "0","1","103",..: 1 15 1 1 2 6 2 1 2 14
> ...
> $ January : Factor w/ 19 levels "0","1","10","114",..: 1 15 1 1 11 12 2 1
> 1 4 ...
> $ July : Factor w/ 16 levels "0","1","122",..: 1 13 1 1 1 12 8 2 1 4
> ...
> $ June : Factor w/ 18 levels "0","1","10","119",..: 1 14 1 1 9 10 9 2 1
> 4 ...
> $ May : Factor w/ 20 levels "0","1","10","111",..: 2 19 1 1 10 15 1 1
> 1 5 ...
> $ September: Factor w/ 19 levels "0","1","11","122",..: 1 18 1 1 14 3 2 1 2
> 9 ...
>
> Thanks& Rg
> Mohan L
>
> [[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.
>
>
--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de
**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
More information about the R-help
mailing list