Convert factor to numeric in R

Post date: Jul 25, 2014 4:50:19 PM

When we want to transform factor to numeric, this function can help:

factor2numeric <- function(x) {   if(class(x) == 'factor') {     return( as.numeric(levels(x)[x]) )   }    return(x) }