I need some help tidying my data. I'm trying to convert some integers to factors (but not all integers to factors). I think I can do with selecting the variables in question but how do I add them back to the original data set? For example, keeping the values NOT selected from my raw_data_tbl and using the mutated types from the raw_data_tbl_int
library(dplyr)
raw_data_tbl %>%
select_if(is.numeric) %>%
select(-c(contains("units"), PRO_ALLOW, RTL_ACTUAL, REAL_PRICE,
REAL_PRICE_HHU, REBATE, RETURN_UNITS, UNITS_PER_CASE, Profit, STR_COST, DCC,
CREDIT_AMT)) %>%
mutate_if(is.numeric, as.factor)
You can use
mutate_at
instead. Here's an example using theiris
dataframe:And the proof:
Honestly, I'd do it like this: