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