# Factor to Numeric

5 messages
Open this post in threaded view
|

## Factor to Numeric

 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]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Factor to Numeric

 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]] > > ______________________________________________ > [hidden email] 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 [hidden email] ********** http://www.for771.uni-bonn.dehttp://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Factor to Numeric

 On Wed, May 26, 2010 at 1:13 PM, Ivan Calandra <[hidden email] > wrote: > Hi, > > What about: > as.numeric(as.character(data\$State)) > ? > What I what is, I want to convert all the column excluding State to factor to numeric in the data frame. So that  I will send  this data frame to another function to total . Any help. Thanks & Rg Mohan L         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.