title: Conditional recode in R
body: <p>I have ten gender variables from <code>2007-2017</code> (<code>gender1</code>, <code>gender2</code>,...,<code>gender17</code>).</p>
  
  <p>I want to create an <strong><code>overall_gender</code></strong> variable equal to the most recent gender record.</p>
  
  <p>Ideally I want to use a loop that says something like: if <code>gender17 = "N/A"</code>, use <code>gender16</code>, if <code>gender16 != "N/A"</code>; and so on.</p>
  
  <p>For example:</p>
  
  <pre><code>       ID y1 y2 y3 y4 y5 y6 y7 y8 y9 y10
  1 person1  M  M  M  M  M  M  M  M  M  NA
  2 person2  M  M  M  M  NA NA NA NA NA NA
  3 person3  F  F  F  F  F  F  NA NA NA NA
  4 person4  M  M  M  M  F  F  F  NA NA NA
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>       ID Gender
  1 person1      M
  2 person2      M
  3 person3      F
  4 person4      F 
  </code></pre>
  
  <p>Any ideas on how to do this? </p>