R: Recoding variables using recode, mutate and case_when
问题 I want to recode the following values < 4 = -1, 4 = 0, > 4 = 1 for the following variables defined by core.vars in the dataset, and still keep the rest of the variables in the data frame. temp.df <- as.tibble (mtcars) other.vars <- c('hp', 'drat', 'wt') core.vars <- c('mpg', 'cyl', 'disp') temp.df <- rownames_to_column (temp.df, var ="cars_id") temp.df <- temp.df %>% mutate_if (is.integer, as.numeric) I have tried a number of ways to implement this. Using case_when , mutate , recode but with