Hi! I have about 100 variables that i would like to dichotomise into, either presence (1) or absence (0) . I found some examples, but they were using the funs argument, which was deprecated. I tried using the list argument but i get an error message.
library(tidyverse)
var_a <- c(0,0,1,3,2,1,3,2,2,0,0,0)
var_a2 <- c(0,1,3,2,0, 0,3,1,2,0,0,0)
var_a3 <- c(0,0,3,0,3,1,2,2,1,0,1,0)
id <- c(1,2,3,4,5,6,7,8,9,10, 11, 12)
df1<- data.frame(var_a,var_a2, var_a3, id )
str(df1)
df1 <- df1 %>%
mutate_at(
vars(starts_with('var_')),
list(case_when(
. == 0 ~ 0,
. > 0 ~ 1)))
"Error in mutate_at()
:
! .funs
must be a one sided formula, a function, or a function name.
Backtrace:
- df1 %>% ...
- dplyr::mutate_at(...)"