title: Create Conditional new variables in R
body: <p>I need to recreate the original variables of a very large data frame (900+ variables).
  Here is an example of what I'm trying to do:</p>
  
  <pre><code>dat &lt;- data.frame(
      id=c('user1','user2','user3'),
      agePanel1=c(20,25,32),
      agePanel2=c(21,NA,33),
      favColPanel1=c('blue','red','blue'),
      favColPanel2=c('red',NA,'red')
      )
  
       id      agePanel1 agePanel2 favColPanel1 favColPanel2
    1 user1        20        21         blue          red
    2 user2        25        NA          red           NA
    3 user3        32        33         blue          red
  </code></pre>
  
  <p>For each variable, I need to create a new variable (age and favCol below) that is NA when there is panel data and is otherwise the first panel observation. In the cases with incomplete panel data, all panel values should be set to NA. The result of this example would look like this :</p>
  
  <pre><code>        id    age  agePanel1 agePanel2 favCol favColPanel1 favColPanel2
      1 user1    NA      20        21      NA        blue          red           
      2 user2    25      NA        NA     red         NA            NA         
      3 user3    NA      32        33      NA        blue          red     
  </code></pre>
  
  <p>I started trying something with dplyr and tidyr :</p>
  
  <pre><code>mutate(dat, age = ifelse(is.na(test$agePanel2),agePanel1,NA))
  </code></pre>
  
  <p>I'm struggling to find a way to do a loop or something that could automate this process. </p>