Recoding the expression of a variable


I am trying to recode an expression of a certain variable. Concretely, in a survey, participants should provide their education degree. For example, "1" is school graduation, "2" is bachelor's degree, "3" is master's degree and "4" is without education degree.

Now I am trying to recode the "4" into a "0" to get an ordinal scaled variable. My data frame is called "SU2021" and the column where the "4" should be changed into a "0" is named D4.

Many thanks in advance!


SU2021$D4 <- ifelse(SU2021$D4 == 4, 0, SU2021$D4)

The logic of the ifelse() is that if D4 is 4, replace it with a 0, otherwise, keep the existing value.

1 Like

This topic was automatically closed 7 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.