title: dplyr, R: Counting a specific value in multiple columns at once
body: <p>I have a data frame:</p>
  
  <pre><code>md &lt;- data.frame(a = c(3,5,4,5,3,5), b = c(5,5,5,4,4,1), c = c(1,3,4,3,5,5),
        device = c(1,1,2,2,3,3))
  myvars = c("a", "b", "c")
  md[2,3] &lt;- NA
  md[4,1] &lt;- NA
  md
  </code></pre>
  
  <p>I want to count number of 5s in each column - by device. I can do it like this:</p>
  
  <pre><code>library(dplyr)
  group_by(md, device) %&gt;% 
  summarise(counts.a = sum(a==5, na.rm = T),
            counts.b = sum(b==5, na.rm = T),
            counts.c = sum(c==5, na.rm = T))
  </code></pre>
  
  <p>However, in real life I'll have tons of variables (the length of <code>myvars</code> can be very large) - so that I can't specify those <code>counts.a</code>, <code>counts.b</code>, etc. manually - dozens of times.</p>
  
  <p>Does <code>dplyr</code> allow to run the count of 5s on all <code>myvars</code> columns at once?</p>
  
  <p>Thank you!</p>