title: create new variables in a dataframe from existing variables using lists of names
body: <p>I was wondering if there was a way to construction a function to do the following:</p>
  <p>Original dataframe, df:</p>
  <pre><code>Obs Col1    Col2
  1   Y       NA
  2   NA      Y
  3   Y       Y
  </code></pre>
  <p>Modified dataframe, df:</p>
  <pre><code>Obs Col1 Col2 Col1_YN Col2_YN
  1   Y    NA   “Yes”   “No”
  2   NA   Y    “No     “Yes”
  3   Y    Y    “Yes”   “Yes”
  </code></pre>
  <p>The following code works just fine to create the new variables but I have lots of original columns with this structure and the “Yes” “No” format works better when constructing tables.</p>
  <pre><code>df$Col1_YN &lt;- as.factor(ifelse(is.na(df$Col1), “No”, “Yes”))
  df$Col2_YN &lt;- as.factor(ifelse(is.na(df$Col2), “No”, “Yes”))
  </code></pre>
  <p>I was thinking along the lines of defining lists of input and output columns to be passed to a function, or using lapply but haven’t figured out how to do this.</p>