I am trying to recode a large number of values in a set of columns in a data frame (df). Columns abc1:abc4 has values from c(1:175, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510). So I want to recode the values as
1:175 = 501, 501:508 = 91, 509 = 92 and 510 - 93 across the four columns (abc1:abc4) at once. Example
df <- data.frame(
id_number = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
age = c(10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
abc1 = c(14, 158, 170, 504, 505, 506, 507, 508, 509, 510),
abc2 = c(501, 502, 501, 501, 45, 501, 502, 59, 501, 100),
abc3 = c(89, 506, 12, 501, 510, 13, 510, 501, 11, 501),
abc4 = c(32, 505, 35, 501, 501, 56, 501, 12, 501, 501)
)
df
What would be the best way to do it (and across all the columns at once)? I can do the recoding one by one but how do you handle large number of values at once? Thanks