I have a df with string (factor) variables like this
id v1 v2 v3 v4
1 1 1 1 0
1 0 0 0 0
1 1 1 1 0
1 1 1 1 0
1 1 1 1 0
What I want is to create a new column that equals 1 or 0 (numeric) if either 1 appears or not on a list of columns say (v2, v3, v4)
id v1 v2 v3 v4 lu
1 1 1 1 0 1
2 0 0 0 0 0
3 1 1 1 0 1
4 0 0 1 0 1
5 1 0 1 0 1
I don't want to convert to numeric (as I need them for future analysis) so something like
df <- df %>% mutate(lu = select(., v2:v4) %>% rowSums(na.rm = TRUE))
df <- df %>% mutate(lu = if_else(lu_1 > 0, 1, lu))
Is not possible. Actually the list of variables to consider is fairly long (around 150)
Thx!