title: how to summarize characters in r
body: <p>I have a data frame:</p>
  
  <pre><code>df &lt;- data.frame(id = c("a","a","a","b","b","b"), survey = rep("1a",6), q1 = c(NA,NA,"y","n",NA,NA),q2 = c("y",NA,NA,NA,"y",NA), q3 = c(NA,"n",NA,NA,NA,"y"))
  </code></pre>
  
  <p>These are survey data which I need to collapse to one for each id and survey. I can get close by:</p>
  
  <pre><code>df %&gt;% group_by(id, survey) %&gt;% summarize_all(toString)
  Source: local data frame [2 x 5]
  Groups: id [?]
  
        id survey        q1        q2        q3
      &lt;fctr&gt; &lt;fctr&gt;     &lt;chr&gt;     &lt;chr&gt;     &lt;chr&gt;
  1      a     1a NA, NA, y y, NA, NA NA, n, NA
  2      b     1a n, NA, NA NA, y, NA NA, NA, y
  </code></pre>
  
  <p>What I really need is:</p>
  
  <pre><code>  id survey q1 q2 q3
  1  a     1a  y  y  n
  2  b     1a  n  y  y
  </code></pre>
  
  <p>The real data frame is fairly large (1.2 million records).</p>
  
  <p>Fundamentally different from <a href="https://stackoverflow.com/questions/13673894/suppress-nas-in-paste">suppress NAs in paste()</a>. Answer to my question not found there.</p>