pct_routine: Calculate percentage by group.

Description Usage Arguments Functions Examples

Description

pct_routine works like count except that it returns group percentages instead of counts. tally_pct is a underlying utility function that corresponds to tally. As the name implies, it also returns percentage.

Usage

1
2
3
4
5
6
7
8
9
pct_routine(data, ..., wt = NULL, ret_name = "pct", rebase = FALSE,
  ungroup = FALSE)

pct_routine_(data, vars, wt = NULL, ret_name = "pct", rebase = FALSE,
  ungroup = FALSE)

tally_pct(data, wt = NULL, ret_name = "pct", rebase = FALSE)

tally_pct_(data, wt = NULL, ret_name = "pct", rebase = FALSE)

Arguments

data

A data.frame or tbl.

...

Variables to group by, see group_by.

wt

Column name of weights.

ret_name

Character of the variable name returned.

rebase

Whether to remove the missing values in the percentage, e.g. rebase the percentage so that NAs in the last group are excluded.

ungroup

Whether to ungroup the returned table.

vars

A character vector of variable names to group by.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data(esoph)
esoph
pct_routine(esoph, agegp, alcgp)
pct_routine(esoph, agegp, alcgp, wt = ncases)
# Crate new grouping variables
pct_routine(esoph, agegp, low_alcgp = alcgp %in% c("0-39g/day", "40-79"))


# This examples shows how rebase works
if (require(dplyr)) {
  iris %>%
    mutate(random_missing = ifelse(rnorm(n()) > 0, NA, round(Sepal.Length))) %>%
    group_by(Species, random_missing) %>%
    tally_pct(wt = Sepal.Width, rebase = TRUE)
}

wangyuchen/extdplyr documentation built on May 4, 2019, 12:58 a.m.