Generalized output formatting with dplyr

Greetings: I am new to dplyr and have some problems formatting my output. Here is a piece of code that creates some reproducible data, using meltto get it in the form I need.

set.seed(1234)
library(reshape2)
library(dplyr)
val <- c(0:1)
a <- sample(val, 99, replace=T)
b <- sample(val, 99, replace=T)
c <- sample(val, 99, replace=T)
d <- sample(val, 99, replace=T)
dat <- data.frame(a,b,c,d)
melt.dat <- melt(dat) 

Now I can complete the required resume:

SummaryTable <- melt.dat %>%
group_by(variable) %>%
summarise_each(funs(sum, sum/n()))

Here is my conclusion:

  variable sum        *
1        a  50 50.50505
2        b  58 58.58586
3        c  46 46.46465
4        d  46 46.46465

My ideal solution would be as follows. I cannot figure out how to specify column names in functions summarise_eachor melt, set decimal place and suppress line numbers. I spent a lot of time getting this far, and it just can't seem like everything else has been figured out!

   Letter Count Percent
        a    50    50.5
        b    58    58.6
        c    46    46.5
        d    46    46.5
+4
source share
1 answer

, dplyr (), :

options(digits = 3)

melt.dat %>%
  group_by(Letter = variable) %>%
  summarise_each(funs(Count = sum(.), Percent = sum(.)/n()*100), -variable)

#Source: local data frame [4 x 3]
#
#  Letter Count Percent
#1      a    45    45.5
#2      b    51    51.5
#3      c    52    52.5
#4      d    48    48.5
+5

All Articles