complete_age_groups: Complete Age Groups

Description Usage Arguments See Also Examples

View source: R/age.R

Description

Completes age groups by adding missing age groups, either within the age range from age_gt to age_lt or using the full age list from seer_std_ages. If the columns age_min or age_max are missing from the input data, separate_age_groups() is first called to expand the age group variable.

Usage

1
2
3
complete_age_groups(data, ..., age_gt = NULL, age_lt = NULL,
  age_group = age_group, fill = list(n = 0), include_unknown = FALSE,
  std_age_groups = fcds_const("age_group"))

Arguments

data

A data frame.

...

Column specification passed on to tidyr::complete(). Used to identify additional columns that should also be completed. Columns that aren't declared here and do not have a default fill value will have NA values in the resulting output.

age_gt

Youngest age (inclusive).

age_lt

Eldest age (inclusive).

age_group

Unquoted column name containing the age grouping.

fill

A named list that for each variable supplies a single value to use instead of NA for missing combinations.

include_unknown

Should the "Unknown" age group be included?

std_age_groups

Character vector containing expected (or standard) age groups.

See Also

Other age processors: filter_age_groups, format_age_groups, recode_age_groups, separate_age_groups, standardize_age_groups

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
dplyr::tibble(
  age_group = c("10 - 14", "15 - 19", "25 - 29"),
  n = 10:12
) %>%
  complete_age_groups(age_gt = 10, age_lt = 35)

set.seed(42)

# Create an example data frame with age_groups at several grouping levels
tidyr::crossing(
  group = LETTERS[1:3],
  sub_group = paste(1:3),
) %>%
  # Add a column with equivalent levels to `sub_group`
  dplyr::mutate(sub_group_equal = letters[as.integer(sub_group)]) %>%
  # Add age groups for ages < 25 to each group level
  tidyr::crossing(
    age_group = fcds_const("age_group")[1:5]
  ) %>%
  # Remove 20% of the age_groups
  dplyr::sample_frac(0.80) %>%
  # Use complete_age_groups() to complete the grouping,
  # using tidyr::complete() syntax to specificy which additional columns
  # are completed.
  complete_age_groups(age_lt = 25, group, tidyr::nesting(sub_group, sub_group_equal))

GerkeLab/fcds documentation built on July 30, 2020, 7:04 p.m.