[R] Factoring a variable

From: Noah Silverman <noahsilverman_at_ucla.edu>
Date: Thu, 17 Jun 2010 12:45:48 -0700


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?


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. Received on Thu 17 Jun 2010 - 20:25:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jun 2010 - 21:40:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive