Assuming the transcoding in the first line should be the same as the rest:
Recode all data columns, create a new data frame as a result:
newdata <- lapply(data,recode,"5=6;4=5;3=4;2=3;1=2;0=1;NA=0")
Name the new data frame based on the old one:
names(newdata) <- gsub("^q","rs",names(newdata))
Combine them:
data <- cbind(data,newdata)
But in fact, you should probably use instead:
newdata <- data newdata[is.na(newdata)] <- 0 newdata <- newdata+1
(not recode ) to do the conversion, and then the rename and cbind .
(This will help if you give a reproducible example.)
source share