Suppose you have a dataframe with variables named X1 - X30 and Y1 - Y30. Each of these variables holds integers 1 - 5. We wish to recode some of the variables starting with X like this:
df %<>%
mutate_at(vars(starts_with("X") &
ends_with("5", "8", "16", "22", "28")),
recode, "1" = 5, "2" = 4, "4" = 2, "5" = 1)
This will, however, return the following error:
Error in UseMethod("recode") :
no applicable method for 'recode' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
This is because recode needs to take a vector as an argument. So what is the way to bypass this?