I'm trying to convert all factor values into numerical in a dataset:
The code is pretty straight forward, I used two methods, both do not return the same level values as they were in factor format:
teenSf2_3 <- mutate_if(teenSf2_2, is.factor, as.numeric)
teenSf2_2[] <- lapply(teenSf2_2, function(x) as.numeric(as.factor(x)))
The result has different level values:
It seems there is an increment of 1 for each level. How do I keep the level values unchanged when converting to numerical?
No comments:
Post a Comment