Recode categorical variable to binary (0/1)

Use ifelse as in:

dat$new1 <- ifelse(dat$Q1==3, 1, 0)

Leave a Comment