In python, scikit has a great function called LabelEncoder that maps categorical levels (strings) to integer representation.
Is there anything in R to do this?
# input P to the function below is a dataframe containing only categorical variables numlevel <- function(P) { n <- dim(P)[2] for(i in 1: n) { m <- length(unique(P[[i]])) levels(P[[i]]) <- c(1:m) } return(P) } Q <- numlevel(P)