Create new variable by multiple conditions via mutate case_when
问题 Hi want to create a new variable/column (WHRcat) by 2 variables (WHR and sexe) under a certain condition wth dyplr, mutate and case_when. Data: WHR sexe WHRcat (new variable) 1.5 1 2.8 2 0.2 2 0.3 1 1.1 1 My code: test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, (WHR < 1.02 & sexe = 1) ~ 2, (WHR >= 0.85 & sexe = 2) ~ 3, (WHR < 0.85 & sexe = 2) ~ 4, TRUE ~ 0)) Though doesnt work. Error: > test<- test%>% mutate(WHRcat = case_when((WHR >= 1.02 & sexe = 1) ~ 1, + (WHR < 1.02