separate_acs | R Documentation |
This is a quick wrapper around tidyr::separate
written to match the standard formatting used for ACS variable labels. These generally take the form e.g. "Total!!Male!!5 to 9 years". This function will separate values by "!!"
and optionally drop the resulting "Total" column, which is generally constant for the entire data frame.
separate_acs(
data,
col = label,
into = NULL,
sep = "!!",
drop_total = FALSE,
...
)
data |
A data frame such as returned by |
col |
Bare column name where ACS labels are. Default: label |
into |
Character vector of names of new variables. If |
sep |
Character: separator between columns. Default: '!!' |
drop_total |
Logical, whether to include the "Total" column that comes from separating ACS data. Default: FALSE |
... |
Any additional arguments to be passed on to |
A data frame
tidyr::separate
## Not run:
if(interactive()){
age <- label_acs(multi_geo_acs("B01001"))
# Default: allow automatic labeling, in this case x1, x2, x3
separate_acs(age)
# Drop Total column, use automatic labeling (x1 & x2)
separate_acs(age, drop_total = TRUE)
# Keep Total column; assign names total, sex, age
separate_acs(age, into = c("total", "sex", "age"))
# Drop Total column; only need to name sex & age
separate_acs(age, into = c("sex", "age"), drop_total = TRUE)
# Carried over from tidyr::separate, using NA in place of the Total column
# will also drop that column and yield the same as the previous example
separate_acs(age, into = c(NA, "sex", "age"))
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.