title: Convert multiple columns to binary in R
body: <p>Hi I have a dataset with multiple columns that are populated with either NA or "Y".  I wish to make these values 0 and 1 respectively.</p>
  
  <p>I am fairly new to R, and trying to determine the best way to loop through these variables and recode them.</p>
  
  <pre><code>STATE&lt;-c(NA, "WA", "NY", NA, NA)  
  x&lt;-c(NA,"Y",NA,NA,"Y")
  y&lt;-c(NA,NA,"Y",NA,"Y")
  z&lt;-c("Y","Y",NA, NA, NA)
  mydata&lt;-data.frame(x,y,z)
  </code></pre>
  
  <p>I have a large dataset, and many of these variables.  However, some of them (such as STATE), I wish to leave alone.  Any help would be greatly appreciated.  Thanks.</p>