Here is the starwars dataset from the dplyr package in R. My goal is to return a column gender where if gender = masculine, then return the values of hair_color adjacent to gender, or if gender = 'feminine', then return the values of skin_color adjacent to gender. If none of those conditions match, just return the existing values of gender. I've tried the following code snippet, but need a bit of assistance. Thanks so much!
library(dplyr)
starwars %>%
mutate(gender =
ifelse(gender == 'masculine', hair_color),
ifelse(gender == 'feminine', skin_color, gender))
Aucun commentaire:
Enregistrer un commentaire