[R] Factoring a variable

Noah Silverman noah at smartmediacorp.com
Thu Jun 17 21:47:50 CEST 2010


Hi,

I have a dataset where the results are coded ("yes", "no")  We want to
do some machine learning with SVM to predict the "yes" outcome

My problem is that if I just use the as.factor function to convert, then
it reverses the levels.

----------------------
x <- c("no", "no", "no", "yes", "yes", "no", "no")
 as.factor(x)
[1] no  no  no  yes yes no  no
Levels: no yes
----------------------
The SVM function (in the e1071 package) sees "no" as the first label and
treats that as the positive outcome. The problem arises when we look at
the decision values of the
predictions.  Everything is gauged as values for "no".
So, is there a way to force R to use my specified order when converting
to factors?
I've tried as.factor(x, levels=c("yes", "no")) but that throws errors
about unused arguments.

Any help?


Thanks



More information about the R-help mailing list