I recoded specific columns in my dataframe using this code:
ptsd_copy %>%
mutate_at(vars(AAQ_1, AAQ_4, AAQ_5, AAQ_6), funs(recode(.,
'never true' = 7,
'often untrue' = 6,
'sometimes untrue' = 5,
'undecided' = 4,
'sometimes true' = 3,
'often true' = 2,
'always true' = 1))) %>%
mutate_at(vars(AAQ_2, AAQ_3, AAQ_7, AAQ_8, AAQ_9), funs(recode (.,
'never true' = 1,
'often untrue' = 2,
'sometimes untrue' = 3,
'undecided' = 4,
'sometimes true' = 5,
'often true' = 6,
'always true' = 7)))
which works perfectly, but I don't really understand the second argument in the mutate_at function. Why do I need to wrap the recode() function inside funs(), and why do I use a period argument inside recode? My understanding is that mutate_at takes a vars() argument and a function to apply to all the columns specified inside vars. So isn't the funs() redundant?
funs
is deprecated. You may needlist(
now, also, it is a anonymous function call, i.e.function(x) recode(x, ..
for that just~ recode(., ..
– akrun