title: How do I remove NAs with the tidyr::unite function?
body: <p>After combining several columns with <code>tidyr::unite()</code>, NAs from missing data remain in my character vector, which I do not want.</p>
  
  <p>I have a series of medical diagnoses per row (1 per column) and would like to benchmark searching for a series of codes <em>via.</em> <code>%in%</code> and <code>grepl()</code>.</p>
  
  <p>There is an open issue on <a href="https://github.com/tidyverse/tidyr/issues/203" rel="nofollow noreferrer">Github</a> on this problem, is there any movement - or work arounds? I would like to keep the vector comma-separated.</p>
  
  <p>Here is a representative example:</p>
  
  <pre><code>library(dplyr)
  library(tidyr)
  
  df &lt;- data_frame(a = paste0("A.", rep(1, 3)), b = " ", c = c("C.1", "C.3", " "), d = "D.4", e = "E.5")
  
  cols &lt;- letters[2:4]
  df[, cols] &lt;- gsub(" ", NA_character_, as.matrix(df[, cols]))
  tidyr::unite(df, new, cols, sep = ",")
  </code></pre>
  
  <p>Current output:</p>
  
  <pre><code># # A tibble: 3 x 3
  #   a     new        e    
  #   &lt;chr&gt; &lt;chr&gt;      &lt;chr&gt;
  # 1 A.1   NA,C.1,D.4 E.5  
  # 2 A.1   NA,C.3,D.4 E.5  
  # 3 A.1   NA,NA,D.4  E.5 
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code># # A tibble: 3 x 3
  #   a     new        e    
  #   &lt;chr&gt; &lt;chr&gt;      &lt;chr&gt;
  # 1 A.1   C.1,D.4    E.5  
  # 2 A.1   C.3,D.4    E.5  
  # 3 A.1   D.4        E.5 
  </code></pre>