title: Create a new column in dplyr by appending values to a list from other columns?
body: <p>I would like to make a new column by appending to a list conditional on the values of other columns. If possible, I would like to do so in <code>dplyr</code>. Sample input and desired output is below. </p>
  
  <p>Suppose a dataframe <code>newdata</code>: </p>
  
  <pre><code>col1 col2 col3 col4
  dog  cat  NA   NA
  NA   cat  foo  bar
  dog  NA   NA   NA
  NA   cat  NA   NA
  </code></pre>
  
  <p>Here is my desired output, with the new column <code>newCol</code>:</p>
  
  <pre><code>col1 col2 col3 col4 newCol
  dog  cat  NA   NA   (dog, cat)
  NA   cat  foo  bar  (cat, foo, bar)
  dog  NA   NA   NA   (dog)
  NA   cat  NA   bar  (cat, bar)
  </code></pre>
  
  <p>I have tried using <code>ifelse</code> within <code>mutate</code> and <code>case_when</code> within <code>mutate</code>, but both will not allow concatenation to a list. Here is my (unsuccessful) attempt with <code>case_when</code>:</p>
  
  <pre><code>newdata = newdata %&gt;% mutate( 
      newCol = case_when(
          col1 == "dog" ~ c("dog"),
          col2 == "cat" ~ c(newCol, "cat"),
          col3 == "foo" ~ c(newCol, "foo"),
          col4 == "bar" ~ c(newcol, "dog")
          )
      )
  </code></pre>
  
  <p>I tried a similar approach with an <code>ifelse</code> statement for each column but also could not append to the list.</p>