I have the following column in a larger tibble (for sake of showing on stackexchange I isolated it in its own tibble)
# A tibble: 36 x 1
`sperm$BMI.Category`
<fct>
1 Normal
2 Normal
3 Normal
4 Obese
5 Overweight
6 Overweight
7 Normal
8 Overweight
9 Overweight
10 Overweight
# ... with 26 more rows
I want to convert them to numeric values so I can use them for statistical work. I was hoping that this would work to replace Underweight with 1
sperm$BMI.Category[sperm$BMI.Category=="Underweight"] <- "1"
I assume an ifelse or something to that effect is going to be the most efficient means to do this? Could somebody please provide the most streamlined manner with minimal code? Also how could one correct the current attempted method for it to be functional?
Aucun commentaire:
Enregistrer un commentaire