Choose the numeric values when you convert a factor variable in R

I would like to convert the factors in my dataframe to numerical values i would choose myself instead of the encoded labels. Does anyone know how to do this? For exaample lets say my variable race is encoded as 1 when black and as 2 when white, and when i convert it as.numeric(race) i would like to set 0 when black and 1 when white?

Asked on August 30, 2020 in R.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.