I tried to combine mutate, case_when and if_any to create a variable = 1 if any of the variables whose name begins with "string" is equal to a specific string. I can't figure out what I'm missing in the combination of these conditions.
I'm trying:
df <-data.frame(string1= c("a","b", "c"), string2= c("d", "a", "f"), string3= c("a", "d", "c"), id= c(1,2,3))
df <- df%>%
mutate(cod = case_when(if_any(starts_with("string") == "a" ~1 )))