That is absolutely brilliant!!! Thank you!
I managed to use this code to recode my variables
library(dplyr)
df %>% mutate_if(is.numeric, ~ .x * 10)
df <- df %>%
mutate_at(vars(starts_with('A')), ~ .x * 10) %>%
mutate_at(vars(starts_with('B')), ~ .x * 10) %>%
mutate_at(vars(starts_with('C')), ~ .x * 10) %>%
mutate_at(vars(starts_with('D')), ~ .x * 10) %>%
mutate_at(vars(starts_with('E')), ~ .x * 10) %>%
mutate_at(vars(starts_with('F')), ~ .x * 10) %>%
mutate_at(vars(starts_with('G')), ~ .x * 10) %>%
mutate_at(vars(ends_with('2')), ~ .x * 10) %>%
mutate_at(vars(ends_with('3')), ~ .x * 10) %>%
mutate_at(vars(ends_with('4')), ~ .x * 10) %>%
mutate_at(vars(ends_with('5')), ~ .x * 10) %>%
mutate_at(vars(ends_with('6')), ~ .x * 10) %>%
mutate_at(vars(ends_with('7')), ~ .x * 10)
Now, I would like to recode all values of -10 to be NAs. I know I could do it one buy one using a code like this:
df$A1[df$A1==-10] <- NA
df$A2[df$A2==-10] <- NA
df$B1[df$B1==-10] <- NA
...
df$D7[df$D7==-10] <- NA
but I hope that I could use mutate-if function again somehow because recoding applies to all the variables above.
Finally, I would like to do a clever recoding into new variables.
Is it possible to recode all numeric variables above into new variables with following logic: 10-60=0, 70-80=50 and 90-100=100? I need new set of recoded variables added to my df with _3 indicator like B2_3, C2_3, D3_3 as they represent 3 levels of responses (1=0, 2=50 and 3=100).
How can I do that?