title: Transpose data frame variables and add null, unique counts in [r]
body: <p>I am trying to build a summary table of a data frame like <code>DataProfile</code> below. 
  The idea is to transform each column into a row and add variables for count, nulls, not nulls, unique, and add additional mutations of those variables.</p>
  
  <p>It seems like there should be a better faster way to do this.  Is there a function that does this? </p>
  
  <pre><code>#trying to write the functions within dplyr &amp; magrittr framework
  library(tidyverse)
  
  mtcars[2,2] &lt;- NA # Add a null to test completeness
  
  # 
  total &lt;- mtcars %&gt;% summarise_all(funs(n())) %&gt;% melt
  nulls &lt;- mtcars %&gt;% summarise_all(funs(sum(is.na(.)))) %&gt;% melt
  filled &lt;- mtcars  %&gt;% summarise_all(funs(sum(!is.na(.)))) %&gt;% melt
  uniques &lt;- mtcars %&gt;% summarise_all(funs(length(unique(.)))) %&gt;% melt
  
  
  mtcars %&gt;% summarise_all(funs(n_distinct(.))) %&gt;% melt
  
  
  #Build a Data Frame from names of mtcars and add variables with mutate
  DataProfile &lt;- as.data.frame(names(mtcars))
  DataProfile &lt;- DataProfile %&gt;% mutate(Total = total$value,
                         Nulls = nulls$value,
                         Filled = filled $value,
                         Complete = Filled/Total,
                         Cardinality = uniques$value,
                         Uniqueness = Cardinality/Total,
                         Distinctness = Cardinality/Filled)
  DataProfile
  
  #These are other attempts with Base R, but they are harder to read and don't play well with summarise_all
  sapply(mtcars, function(x) length(unique(x[!is.na(x)]))) %&gt;% melt
  rapply(mtcars,function(x)length(unique(x))) %&gt;% melt
  </code></pre>