Skip to contents

collapse_acs_variables() uses forcats::fct_collapse() to aggregated variables while creating a new label column. Other variables are retained in list columns of unique values. The aggregated values for perc_moe may not be accurate after transformation with this function.

Usage

collapse_acs_variables(
  data,
  ...,
  other_level = NULL,
  name_col = "NAME",
  variable_col = "variable",
  label_col = "label",
  value_col = "estimate",
  moe_col = "moe",
  na.rm = TRUE,
  digits = 2
)

Arguments

data

ACS data frame input.

...

<dynamic-dots> A series of named character vectors. The levels in each vector will be replaced with the name.

other_level

Value of level used for "other" values. Always placed at end of levels.

name_col

Name column name, Default: 'NAME'

variable_col

Variable column name, Default: 'variable'

label_col

Label column name, Default: 'label'. Label is a factor column added to the returned data frame.

value_col, moe_col

Value and margin of error column names (default to "estimate" and "moe").

na.rm

Passed to sum(), Default: TRUE

digits

Passed to round(), Default: 2

Examples

if (FALSE) {
if (interactive()) {
  edu_data <- get_acs_tables(
    "county",
    table = "B15003",
    state = "MD",
    county = "Baltimore city"
  )

  table_vars <- acs_table_variables("B15003")

  collapse_acs_variables(edu_data,
    "total" = table_vars[1],
    "second" = table_vars[2],
    "third and fourth" = table_vars[3:4],
    "next 5" = table_vars[5:10],
    other_level = "Other"
  )
}
}