How can I make the following changes for multiple or all variables?
- change "yes" to 1
- change "no" to 0
- keep NAs
I tried recode but it seems not to be appliable to dataframes.
How can I make the following changes for multiple or all variables?
I tried recode but it seems not to be appliable to dataframes.
x <- data.frame(y=sample(c("yes", "no", "NA"), 10, replace = TRUE))
library(tidyr)
x$y2<- recode_factor(x$y, yes=1, no=0)