[R] nominal to numeric function

Phil Spector spector at stat.berkeley.edu
Wed Aug 12 18:10:18 CEST 2009


It's generally safer to use

        as.numeric(as.character(variablename))

since it eliminates problems associated with factors.

                                        - Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Wed, 12 Aug 2009, Daniel Malter wrote:

>
> Hi you can use newvariable=as.numeric(variablename). This converts your
> factors into numeric variables, but not always with the desired result. So
> make sure that you check whether "newvariable" gives you what you want.
> Otherwise recoding by hand is indicated.
>
> Best,
> Daniel
>
>
>
> Noah Silverman-3 wrote:
>>
>> Hi,
>>
>> I'm training an SVM (C-classification from e1071 library)
>>
>> Some of the variables in my data set are nominal.  Is there some
>> easy/automatic way to convert them to numerical representations?
>>
>> Thanks,
>>
>> -N
>>
>> ______________________________________________
>> 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.
>>
>>
>
> --
> View this message in context: http://www.nabble.com/nominal-to-numeric-function-tp24930466p24939723.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list