I have 4 variables: V1, V2, V3, V4
I want to create a variable "group" where the largest value of V1:V4 = 1, the second largest = 2, ... the smallest = 4.
When I was previously working with only V1 & V2, I used the syntax: df = df %>% mutate (group = ifelse(df$V1 > df$V2, 1, 2))
However, I don't know how to expand this type of statement (I am a newcomer to R).
Many thanks.
Aucun commentaire:
Enregistrer un commentaire