-9

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.

Patrick Balada
  • 1,330
  • 1
  • 18
  • 37
  • 5
    Just `as.integer(columnname == "yes")`. Also: Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Feb 27 '18 at 10:29

1 Answers1

1
x <- data.frame(y=sample(c("yes", "no", "NA"), 10, replace = TRUE))
library(tidyr)
x$y2<- recode_factor(x$y, yes=1, no=0)
Marko
  • 387
  • 1
  • 3
  • 13