title: R: Cleaning up a wide and untidy dataframe
body: <p>I have a data frame that looks like: </p>
  
  <pre><code>d&lt;-data.frame(id=(1:9), 
                    grp_id=(c(rep(1,3), rep(2,3), rep(3,3))), 
                    a=rep(NA, 9), 
                    b=c("No", rep(NA, 3), "Yes", rep(NA, 4)), 
                    c=c(rep(NA,2), "No", rep(NA,6)), 
                    d=c(rep(NA,3), "Yes", rep(NA,2), "No", rep(NA,2)), 
                    e=c(rep(NA, 7), "No", NA), 
                    f=c(NA, "No", rep(NA,3), "No", rep(NA,2), "No"))
  &gt;d
    id grp_id  a    b    c    d    e    f
  1  1      1 NA   No &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  2  2      1 NA &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;   No
  3  3      1 NA &lt;NA&gt;   No &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  4  4      2 NA &lt;NA&gt; &lt;NA&gt;  Yes &lt;NA&gt; &lt;NA&gt;
  5  5      2 NA  Yes &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  6  6      2 NA &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;   No
  7  7      3 NA &lt;NA&gt; &lt;NA&gt;   No &lt;NA&gt; &lt;NA&gt;
  8  8      3 NA &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;   No &lt;NA&gt;
  9  9      3 NA &lt;NA&gt; &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;   No
  </code></pre>
  
  <p>Within each group (grp_id) there is only 1 "Yes" or "No" value associated with each of the columns a:f.</p>
  
  <p>I'd like to create a single row for each grp_id to get a data frame that looks like the following: </p>
  
  <pre><code>grp_id  a    b    c    d    e    f
       1 NA   No   No &lt;NA&gt; &lt;NA&gt;   No
       2 NA  Yes &lt;NA&gt;  Yes &lt;NA&gt;   No
       3 NA &lt;NA&gt; &lt;NA&gt;   No   No   No
  </code></pre>
  
  <p>I recognize that the tidyr package is probably the best tool and the 1st steps are likely to be</p>
  
  <pre><code>d %&gt;% 
     group_by(grp_id) %&gt;%
       summarise()
  </code></pre>
  
  <p>I would appreciate help with the commands within summarise, or any solution really.  Thanks. </p>