Jim Lemon
2000-Apr-28 12:53 UTC
[R] converting numerical parts of factors into numeric vector
This is a bit of a roughie, but it might do what you want. test<-as.factor(c(1,2,3,4,5,"YES","NO","MAYBE",9,10)) fact2num<-function(f) { if(!missing(f)){ if(is.factor(f)) { fnew<-vector("numeric",length(f)) for(i in 1:length(f)) fnew[i]<-as.numeric(as.character(f[i])) return(fnew) } } cat("Usage: fact2num(f)\n\twhere f is a factor vector\n") } fact2num(test) Please loftily ignore the error messages. Jim -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._