how to factors to numeric in R code example Example: R factors as numeric as.numeric(levels(f))[f] # f being the factor column