generations: Convert year of birth to generations

Description Usage Arguments Details Value Examples

View source: R/generations.R

Description

This is the main function in this package. It will convert one or more years to the corresponding generation. Generation names and years are taken from Howe & Strauss' generational theory.

Usage

1
2
3
4
5
6
7
8
generations(
  yob,
  full_names = FALSE,
  years = FALSE,
  years_sep = " ",
  years_range_sep = "–",
  as_factor = TRUE
)

Arguments

yob

a vector of integers. Currently, integers are the only accepted input, so characters and date types must be converted first.

full_names

logical. If TRUE, the generation name will typically have the word "generation" at the end (e.g., "Millennial" becomes "Millennial Generation"). "Gen X" (together with Y and Z) expands to "Generation X". FALSE by default.

years

logical. Should the year range be included in the output? Useful for printing, plotting, or otherwise displaying. For example, "Gen X" becomes "Gen X (1964–1983)". FALSE by default.

years_sep

a string. If years is TRUE, what should the separator between the generation name and opening parenthesis in the year range be? A single space by default, but it may look better in a visual if a new line character (backslash + n) is used.

years_range_sep

a string. If years is TRUE, what should go between the start and end years. By default, an en-dash ("–"). For more print-friendly characters, try a hyphen.

as_factor

logical. Should the vector be returned as a factor? If so, the levels will be chronological order (oldest generation first). If not, it will be returned as a character vector. TRUE by default.

Details

Note that labels are included for years between 1435 and 2030. Anything outside of that range will return NA.

Value

a vector

Examples

1
2
3
4
5
6
7
8
# Generate some sample data
yobs <- sort(floor(runif(10, 1880, 2020)))

# Convert to the generations
generations(yobs)
generations(yobs, full_names = TRUE)
generations(yobs, full_names = TRUE, years = TRUE)
generations(yobs, years = TRUE, years_range_sep = " to ")

JoeyStanley/generations documentation built on Dec. 31, 2020, 2:03 p.m.