title: Combine column to remove NA's
body: <p>I have some columns in R and for each row there will only ever be a value in one of them, the rest will be NA's. I want to combine these into one column with the non-NA value. Does anyone know of an easy way of doing this. For example I could have as follows:</p>
  
  <pre><code>data &lt;- data.frame('a' = c('A','B','C','D','E'),
                     'x' = c(1,2,NA,NA,NA),
                     'y' = c(NA,NA,3,NA,NA),
                     'z' = c(NA,NA,NA,4,5))
  </code></pre>
  
  <p>So I would have</p>
  
  <pre><code>'a' 'x' 'y' 'z'  
   A   1   NA  NA  
   B   2   NA  NA  
   C  NA   3   NA  
   D  NA   NA  4  
   E  NA   NA  5
  </code></pre>
  
  <p>And I would to get</p>
  
  <pre><code> 'a' 'mycol'  
    A   1  
    B   2  
    C   3  
    D   4  
    E   5  
  </code></pre>
  
  <p>The names of the columns containing NA changes depending on code earlier in the query so I won't be able to call the column names explicitly, but I have the column names of the columns which contains NA's stored as a vector e.g. in this example <code>cols &lt;- c('x','y','z')</code>, so could call the columns using <code>data[, cols]</code>.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks</p>