title: Combine non NA values for n Lists R
body: <h2>A -  I have a list containing <code>igraph</code> graph objects:</h2>
  
  <pre><code>goodgg
  
  [[1]]
  IGRAPH UN-- 3 3 -- 
  + attr: name (v/c), color (v/c), value (e/n), sourceID (e/n), targetID (e/n)
  + edges (vertex names):
  [1] 89315--89316 89315--89928 89316--89928
  
  [[2]]
  IGRAPH UN-- 3 2 -- 
  + attr: name (v/c), color (v/c), value (e/n), sourceID (e/n), targetID (e/n)
  + edges (vertex names):
  [1] 106277--106278 106278--106279
  </code></pre>
  
  <h2>I can combine these into a single object using <code>[union][1]</code>:</h2>
  
  <pre><code>combine = graph.union(goodgg[[1]], goodgg[[2]], byname=T)
  
  combine
  IGRAPH UN-- 6 5 -- 
  + attr: color_1 (v/c), color_2 (v/c), name (v/c)
  + edges (vertex names):
  </code></pre>
  
  <h2>From this, I can extract particular attributes e.g. a <code>color</code>, which lines up with the order of the original objects (1 - 2):</h2>
  
  <pre><code>as.list(get.vertex.attribute(combine))
  $color_1
  [1] "red"    "red"    "orange" NA       NA       NA      
  
  $color_2
  [1] NA    NA    NA    "red" "red" "red"
  
  $name
  [1] "89315"  "89316"  "89928"  "106277" "106278" "106279"
  </code></pre>
  
  <h2>How can I extract the non <code>NA</code> values in <code>$color_1</code> and <code>$color_2</code> and merge them into a new list when I have an arbitrary number of <code>color_n</code> entries? (E.g. I have n entries)?</h2>
  
  <p>To get:</p>
  
  <pre><code>[1] "red"    "red"    "orange" "red"    "red"    "red"
  </code></pre>
  
  <h2>What I tried (which does not work for <code>n</code> <code>color_</code> variables:</h2>
  
  <p>In this simple case I can do what <a href="https://stackoverflow.com/questions/26896087/union-of-igraph-objects-loses-attributes">this</a> answer did here:</p>
  
  <pre><code>V(combine)$color &lt;- ifelse(is.na(get.vertex.attribute(combine)$color_1), get.vertex.attribute(combine)$color_2,get.vertex.attribute(combine)$color_1)
  
  get.vertex.attribute(combine)$color
  [1] "red"    "red"    "orange" "red"    "red"    "red" 
  </code></pre>
  
  <p>However, in reality my list could have <code>n</code> elements. How can I adjust this to account for <code>n</code> elements?</p>
  
  <p>I considered using multiple nested IFELSE statements such as <a href="https://stackoverflow.com/questions/18012222/nested-ifelse-statement-in-r">here</a> and <a href="http://www.dummies.com/programming/r/how-to-chain-ifelse-statements-in-r/" rel="nofollow noreferrer">here</a> a la:</p>
  
  <pre><code>V(combine)$color &lt;- ifelse(is.na(get.vertex.attribute(combine)$color_1), ifelse(is.na(get.vertex.attribute(combine)$color_2), ifelse(get.vertex.attribute(combine)$color_3)......))
  </code></pre>
  
  <p>This does not work for unknown <code>n</code> attributes and does not solve the issue of having an unknown number <code>n</code> of attributes to work with.</p>
  
  <p>Many thanks for your help.</p>