ezsummary

Introduction

Hadley's dplyr provides a grammar to talk about data manipulation and another his package, tidyr provides a mindset to think about data. These two tools really makes it a lot easier to perform data manipulation today. This package ezsummary packed up some commonly used dplyr and tidyr steps to generate data summarization to help you save some typing time. It also comes with some table decoration tolls that basically allows you to pipe the results directly into a table generating function like knitr::kable() to render out.

For example, if you only use dplyr and tidyr to generate a statistical summary table by group. You need to go through the following steps.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tidyr)

mtcars %>%
  select(cyl, mpg, wt, hp) %>%
  group_by(cyl) %>%
  summarize_each(funs(mean, sd)) %>%
  gather(variable, value, -cyl) %>%
  mutate(value = round(value, 3)) %>%
  separate(variable, into = c("variable", "analysis")) %>%
  spread(analysis, value) %>%
  mutate(variable = factor(variable, levels = c("mpg", "wt", "hp"))) %>%
  arrange(variable, cyl) %>%
  kable()
cylvariablemeansd
4mpg26.6644.510
6mpg19.7431.454
8mpg15.1002.560
4wt2.2860.570
6wt3.1170.356
8wt3.9990.759
4hp82.63620.935
6hp122.28624.260
8hp209.21450.977

For people who are familar with "tidyverse", I'm sure the above codes are very straightforward. However, it's a bit annoying to type it again and again. With ezsummary, you don't need to think too much about it. You can just type:

library(ezsummary)

mtcars %>%
  select(cyl, mpg, wt, hp) %>%
  group_by(cyl) %>%
  ezsummary() %>%
  kable()
cylvariablemeansd
4mpg26.6644.510
6mpg19.7431.454
8mpg15.1002.560
4wt2.2860.570
6wt3.1170.356
8wt3.9990.759
4hp82.63620.935
6hp122.28624.260
8hp209.21450.977

To install

    install.packages("ezsummary")

Or

    install.packages("devtools")
    devtools::install_github("haozhu233/ezsummary")

To use

Here, I will show another quick demo of how to use this package here. For detailed package documentation, please check the package vignette.

library(dplyr)
library(ezsummary)

mtcars %>%
  # q: quantitative/continuous variables; c: categorical variables
  var_types("qcqqqqqcccc") %>%
  group_by(am) %>%
  ezsummary(flavor = "wide", unit_markup = "[. (.)]",
            digits = 1, p_type = "percent") %>%
  kable(col.names = c("variable", "Manual", "Automatic"))
variableManualAutomatic
mpg17.1 (3.8)24.4 (6.2)
cyl_43 (15.8%)8 (61.5%)
cyl_64 (21.1%)3 (23.1%)
cyl_812 (63.2%)2 (15.4%)
disp290.4 (110.2)143.5 (87.2)
hp160.3 (53.9)126.8 (84.1)
drat3.3 (0.4)4 (0.4)
wt3.8 (0.8)2.4 (0.6)
qsec18.2 (1.8)17.4 (1.8)
vs_012 (63.2%)6 (46.2%)
vs_17 (36.8%)7 (53.8%)
gear_315 (78.9%)0 (0)
gear_44 (21.1%)8 (61.5%)
gear_50 (0)5 (38.5%)
carb_13 (15.8%)4 (30.8%)
carb_26 (31.6%)4 (30.8%)
carb_33 (15.8%)0 (0)
carb_47 (36.8%)3 (23.1%)
carb_60 (0)1 (7.7%)
carb_80 (0)1 (7.7%)

Issues

If you ever find any issues, please feel free to report it in the issues tracking part on github. https://github.com/haozhu233/simple.summary/issues.

Thanks for using this package!

Copy Link

Version

Down Chevron

Install

install.packages('ezsummary')

Monthly Downloads

31

Version

0.2.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

July 11th, 2016

Functions in ezsummary (0.2.1)