recode_age_groups: Recode Age Groups

Description Usage Arguments See Also Examples

View source: R/age.R

Description

This function helps to recode age groups into new groups that are equal to or overlap the original age grouping.

Usage

1
recode_age_groups(data, breaks, age_group = age_group)

Arguments

data

A data frame, containin age group labels in the age_group column.

breaks

The breaks at which the lower bounds of age groups should be defined. If the first and last elements are NA, the lower bound is learned from the age groups present in the data. (Both, one, or none can be NA). If the first element is not missing, the lowest group will be ages 0 to min(breaks) - 1. If the last element is not missing, the highest group will be max(breaks) and above. Missing values within the breaks other than the first and last elements are ignored. The order of the breaks is not important beyond the presence of missing values at the extremes.

age_group

Unquoted column name containing the age grouping.

See Also

Other age processors: complete_age_groups, filter_age_groups, format_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
d_age_groups <- dplyr::tibble(
  age_min = seq(0, 25, 5),
  age_max = seq(4, 29, 5)
) %>%
  format_age_groups()

d_age_groups

recode_age_groups(d_age_groups, breaks = c(10, 20, 25))

# Use maximum age in data for upper bound of highest group
recode_age_groups(d_age_groups, breaks = c(10, 20, 25, NA))

# Use minimum age in data for lower bound of lowest group
d_age_groups %>%
  dplyr::filter(age_min >= 5) %>%
  recode_age_groups(breaks = c(NA, 10, 20, 25))

# Dichotomize
recode_age_groups(d_age_groups, breaks = 20)

d_age_groups %>%
  dplyr::filter(age_min >= 5) %>%
  recode_age_groups(breaks = c(NA, 20, NA))

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