I have a dataframe for a likert scale questionnarie. All of the questions have a 1-10 scale, but to run some analyses I want to recode the scale to be from 1 to 5.
So, I want to recode most of the variables of my data frame, excluding identification variables. I've tried several things and looked also into past threads but I cannot find a solution, I always get an error.
Since I'm new to R I believe it is just a rookie mistake but I hope you can help me.
Here is the code:
z <- data.frame (ID = c(23,24,25,26,27),
Project = c("EA","EA","PLA","PLA","PLA"),
Q1 = c(3,9,8,5,10),
Q2 = c(1,2,6,7,9),
Q3 = c(4,8,6,6,10))
recode_z <- z[,3:5]
p3[,recode_p3] <- as.data.frame(lapply(p3[, recode_p3], function(x)ifelse(x == 2, 1),
ifelse(x == 3, 2),
ifelse(x== 4, 2),
ifelse(x== 5, 3),
ifelse(x== 6, 3),
ifelse(x== 7, 4),
ifelse(x== 8, 4),
ifelse(x== 9, 5),
ifelse(x== 10, 5,x)))
I get this error:
Error in .subset(x, j) : invalid subscript type 'list'
Can you spot the mistake? Thank you in advance!