Function takes output of [get_acs()] and makes series of variable transformations according to specification provided by the `dictionary` argument. This function recognizes groups of variables by the `concept_short` column. Variables that have the same name in `combined_var` column are summarized prior to other transformations. Next, variables from each `concept_short` group is divided by the value of the variable that name ends with `"_n"`. Exceptions are made for variables which names begins with: `"agg_"`, `"avg_"`, `"med_"` and `"mean_"`. Those are treated *as is*.
Some of the `concept_short` groups are made of only a single variable. In this case they will be treated *as is* or can be divided by a common denominator (usually `population` variable). To indicate which variables should be adjusted, set `adj_other_vars = TRUE` and pass quoted or unquoted variable names to `vars_to adjust`. You will also need to specify which variable should be treated as the denominator by passing quoted or unquoted variable name to `vars_denominator`.
Usage
geo_tidy_acs_data(
data,
dictionary,
geo_type = c("zipcode", "county", "state", "region"),
adj_other_vars = FALSE,
vars_to_adjust,
vars_denominator
)Arguments
- data
Data.frame or tibble – result of [get_acs()] function.
- dictionary
Data.frame or tibble containing at least `name`, `concept_short`, `var_name`, and `combined_var` columns. Please check the vignette for more details.
- geo_type
Character. Name of the geography of `data`. Can be one of: `zipcode` (default), `state`, `county` or `region`.
- adj_other_vars
Logical. Default `FALSE`. In the case `data` contains single variables that needs to be related to other variables (e.g. `children_u18` to `population`) please set to `TRUE` and pass correct names to `vars_to_adjust` and `vars_denominator.`
- vars_to_adjust
Quoted or unquoted vector of variables names to adjust.
- vars_denominator
Unquoted variable name that will be used as common denominator for variables indicated in `vars_to_adjust`.
Value
A tibble with *geography* column/s (`zipcode`, `state`, `county`, `region`) and cleaned variables specified in `data.frame` passed to `dictionary` argument.
Examples
if (FALSE) { # \dontrun{
# Use internal state dataset
data("ds_state_acs_raw")
# Download zipcode dataset from S3
ds_zip_acs_raw <- geo_read_s3("ds_zip_acs_raw.csv", readr::read_csv)
# Tidy variables from state set. Also adjust children_u18 and pop_u18
# variables by dividing them by population.
geo_tidy_acs_data(
data = ds_state_acs_raw,
dictionary = geo_dictionary,
geo_type = "state",
vars_to_adjust = c(children_u18, pop_u18),
vars_denominator = population,
adj_other_vars = TRUE
)
# Tidy variables from zipcode data set. Do not specify additional variables
# to adjust.
geo_tidy_acs_data(
data = ds_zip_acs_raw,
dictionary = geo_dictionary,
geo_type = "zipcode",
adj_other_vars = FALSE
)
} # }