I have multiple columns with variables I need to reverse-code. Let's say my column names are A,B,C,D and each column has a mix of values from 1-4. I am trying to recode all the 4's as 1's, 3's as 2's. etc.
I am able to do it like this:
`dataNew$A <- as.numeric(dataNew$A)
levels(dataNew$A)[levels(dataNew$A)=="1"] <- "4"
levels(dataNew$A)[levels(dataNew$A)=="2"] <- "3"
levels(dataNew$A)[levels(dataNew$A)=="3"] <- "2"
levels(dataNew$A)[levels(dataNew$A)=="2"] <- "1"`
Then I could repeat for columns B, C, D
However, I'm wondering if there is a cleaner way to do this where I can change multiple numbers or multiple columns and numbers at once, rather than individually writing the above code for each column/number combination.