recoding items in the data doesn't work


I have three items that need to be recoded:
data$tweede_lockdown_1_w2<-as.factor(recode_factor(data$tweede_lockdown_1_w2,'2'='1', '3'='2','6'='3','7'='4','8'='5'))
data$tweede_lockdown_2_w2.r<-as.factor(recode_factor(data$tweede_lockdown_2_w2.r,'2'='1', '3'='2','6'='3','7'='4','8'='5'))
data$tweede_lockdown_3_w2<-as.factor(recode_factor(data$tweede_lockdown_3_w2,'2'='1', '3'='2','6'='3','7'='4','8'='5'))
But, when I do that, I see that nothing has changed in the data.

Does anyone know what I should do differently?

Thanks in advance!

although the use of as.factor is unecesary and can be removed, and the mix of dplyr and base R seems odd (given the particular context where the same transformation is repeated and purer dplyr use would be more concise), I can't see anything syntactically wrong with your code to where it wouldnt be changing.

# example data 
data <- data.frame(tweede_lockdown_1_w2=factor(2))


[1] 2
Levels: 2

your code:

data$tweede_lockdown_1_w2 <- as.factor(recode_factor(data$tweede_lockdown_1_w2,'2'='1', '3'='2','6'='3','7'='4','8'='5'))


> data$tweede_lockdown_1_w2
[1] 1
Levels: 1

Thank you for your response!

The problem is that although I recoded for example the 2 to 1, it seems like it hasn't changed, because the minimum value is still 2 and the maximum value is 8 (which should not be possible, because the maximum value I insurted was 5).

Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
2.000 6.000 7.000 6.454 8.000 8.000 127

Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
2.000 3.000 6.000 5.448 7.000 8.000 126
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
2.00 2.00 3.00 4.13 6.00 8.00 127

Would you know what I could do to change this?

Thank you for your time!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.