calc_shares: Make table of rates given a denominator

Description Usage Arguments Value Examples

View source: R/calc_shares.R

Description

calc_shares makes it easy to divide values by some denominator within the same long-shaped data frame. For example, it works well for a table of population groups for multiple locations where you want to divide population counts by some total population. It optionally handles dividing margins of error. Denote locations or other groupings by using a grouped data frame, passing bare column names to ..., or both.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
calc_shares(
  .data,
  ...,
  group = group,
  denom = "total_pop",
  value = estimate,
  moe = NULL,
  digits = 3,
  estimate = NULL
)

Arguments

.data

A data frame

...

Optional; bare column names to be used for groupings.

group

Bare column name where groups are given–that is, the denominator value should be found in this column

denom

String; denominator to filter from group

value

Bare column name of values. Replaces estimate argument, but (for now) still defaults to a column named estimate

moe

Bare column name of margins of error; if supplied, MOE of shares will be included in output

digits

Number of digits to round to; defaults to 3.

estimate

Soft deprecated; use value. Bare column name of estimates or values

Value

A tibble/data frame with shares (and optionally MOE of shares) of subgroup values within a denominator group. Shares given for denominator group will be blank.

Examples

1
2
3
4
5
6
7
8
edu %>%
  dplyr::group_by(name) %>%
  calc_shares(group = variable, denom = "age25plus",
              value = estimate, moe = moe)

race_pops %>%
  calc_shares(name, group = variable, denom = "total",
              value = estimate, moe = moe)

camille-s/camiller documentation built on Jan. 22, 2022, 6:50 a.m.