acs_drop_vars: Drop ACS variable columns from dataframe

Description Usage Arguments Details Examples

View source: R/acs_vars.R

Description

Simple wrapper of dplyr::select() to drop ACS variable columns (estimates or margins) created by acs_transform().

Usage

1
2
3
4
acs_drop_vars(
  .data,
  type = c("all", "estimates", "margins", "standard errors")
)

Arguments

.data

[data.frame]: A data.frame with ACS variable columns using the format created by acs_transform(): b25002_e001 for estimates and b25002_m001 for margins.

type

[character(1)]: The type of columns to drop. Must be one of: "all", "estimates", "margins", or "standard errors"

Details

This function simply wraps the dplyr expression select(df, -matches("pattern")), where the regular expression is "[bc]\\d{5}[a-z]*_e\\d{3}" for estimates and "[bc]\\d{5}[a-z]*_m\\d{3}" for margins.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(dplyr)

df <- tibble(
  year = 2009L,
  span = 1L,
  b25070_e001 = c(1, 2, 3),
  b25070_m001 = c(0.2, 0.5, 0.7),
  b25070_e002 = c(3, NA, 1),
  b25070_m002 = c(0.1, NA, 0.4)
)

acs_drop_vars(df, "estimates")

acs_drop_vars(df, "margins")

df %>%
  mutate(foo = acs_est_sum("b25070_e{1:2*}")) %>%
  acs_drop_vars("all")

austensen/acssf documentation built on Nov. 18, 2020, 4:44 a.m.