Reduce the dimensionality of the table

collapse_table(
  poptable,
  area_var,
  X_vars,
  count_var,
  report = "counts",
  new_name = "n_aggregate",
  warnings = FALSE
)

Arguments

poptable

The population table, collapsed in terms of counts. Must contain all variables in the RHS of formula, as well as the variables specified in area_var and count_var below.

area_var

A character vector of the area of interest.

X_vars

A character vector of the variables to keep. By design, this should be fewer variables than what is available in poptable.

count_var

A character variable that specifies which variable in poptable indicates the count

report

Should the output be in simple counts (the default, "counts") or the proportion that count represents in the area ("proportions")?

new_name

What should the new count (or proportion) variable be called?

warnings

Show some warnings about zero cells in the original data? Defaults to FALSE

Value

A dataframe of counts or proportions. By design, it will include the variables area_var, X_vars, and whatever is specified in new_name.

Examples

# If you want to estimate education by female and age collapse_table(acs_race_NY, area_var = "cd", X_vars = c("female", "age"), count_var = "count")
#> # A tibble: 270 × 4 #> cd female age n_aggregate #> <chr> <int> <fct> <dbl> #> 1 NY-01 0 18 to 24 years 34123 #> 2 NY-01 0 25 to 34 years 45361 #> 3 NY-01 0 35 to 44 years 41146 #> 4 NY-01 0 45 to 64 years 104998 #> 5 NY-01 0 65 years and over 57557 #> 6 NY-01 1 18 to 24 years 32579 #> 7 NY-01 1 25 to 34 years 42309 #> 8 NY-01 1 35 to 44 years 42232 #> 9 NY-01 1 45 to 64 years 104236 #> 10 NY-01 1 65 years and over 71758 #> # … with 260 more rows
# Report proportions collapse_table(acs_race_NY, area_var = "cd", X_vars = c("female", "age"), count_var = "count", report = "proportions", new_name = "prop_in_cd")
#> Warning: You asked for proporitons but the value of `new_name` looks more appropriate for a count.
#> # A tibble: 270 × 4 #> cd female age prop_in_cd #> <chr> <int> <fct> <dbl> #> 1 NY-01 0 18 to 24 years 0.0592 #> 2 NY-01 0 25 to 34 years 0.0787 #> 3 NY-01 0 35 to 44 years 0.0714 #> 4 NY-01 0 45 to 64 years 0.182 #> 5 NY-01 0 65 years and over 0.0999 #> 6 NY-01 1 18 to 24 years 0.0565 #> 7 NY-01 1 25 to 34 years 0.0734 #> 8 NY-01 1 35 to 44 years 0.0733 #> 9 NY-01 1 45 to 64 years 0.181 #> 10 NY-01 1 65 years and over 0.125 #> # … with 260 more rows