title: r - using summarise_each() to count records ignoring NAs
body: <p>Is there a way to use <code>summarise_each()</code> to count the number of records in a data frame, but ignore <code>NA</code>s?</p>
  
  <p><strong>Example / Sample Data</strong></p>
  
  <pre><code>df_sample &lt;- structure(list(var_1 = c(NA, NA, NA, NA, 1, NA), var_2 = c(NA, 
    NA, NA, NA, 2, 1), var_3 = c(NA, NA, NA, NA, 3, 2), var_4 = c(NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), var_5 = c(NA, 
    NA, NA, NA, 4, 3)), .Names = c("var_1", "var_2", "var_3", "var_4", 
    "var_5"), row.names = 5:10, class = "data.frame")
  
  &gt; df_samp
     var_1 var_2 var_3 var_4 var_5
  5     NA    NA    NA    NA    NA
  6     NA    NA    NA    NA    NA
  7     NA    NA    NA    NA    NA
  8     NA    NA    NA    NA    NA
  9      1     2     3    NA     4
  10    NA     1     2    NA     3
  </code></pre>
  
  <p>Using <code>summarise_each()</code> and <code>n()</code> counts all the records:</p>
  
  <pre><code>library(dplyr)
  df_samp %&gt;%
    summarise_each(funs(n()))
  
  ## result:
     var_1 var_2 var_3 var_4 var_5
  1     6     6     6     6     6
  </code></pre>
  
  <p>I know that <code>n()</code> doesn't accept arguments, therefore is there another method I can use within <code>summarise_each()</code> that will ignore the <code>NA</code>s when counting the number of records, and will return zero if the variable is all <code>NA</code>?</p>
  
  <p><strong>Desired Result</strong></p>
  
  <pre><code>   var_1 var_2 var_3 var_4 var_5
  1     1     2     2     0     2
  </code></pre>
  
  <p>The following method gets me part of the way there, but I would also like to return a 0 for <code>var_4</code>:</p>
  
  <pre><code>df_samp %&gt;%
    melt %&gt;%
    filter(!is.na(value)) %&gt;%
    group_by(variable) %&gt;%
    summarise(records = n())
  
  ## result:
    variable records
  1    var_1       1
  2    var_2       2
  3    var_3       2
  4    var_5       2
  </code></pre>