I have dataset with app interactions for different users. App interactions are saved as the number of days the feature has been interacted with by a user, for a specific week. Sample table looks like (commented out ID and weeknr for practical purposes):
tibble(
#id = (1, 1, 1),
#weeknr = (1, 2, 3),
var_1 = c(1, 2, 3, 2, 1),
var_2 = c(0, 0, 1, 4, 0),
var_3 = c(1, 1, 1, 0, 0)
)
Goal is now to create three new columns, based on var_{1|3}. If count on app interactions is > 1, assign 1 otherwise 0. I tried the following with no success:
tibble(
var_1 = c(1, 2, 3, 2, 1),
var_2 = c(0, 0, 1, 4, 0),
var_3 = c(1, 1, 1, 0, 0)
) %>%
mutate_all(
funs(case_when(
. > 0 ~ 1,
. == 0 ~ 0,
TRUE ~ NA
))
)
Any help is much appreciated!