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.

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.

Value

a vector

Details

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

Examples

# Generate some sample data yobs <- sort(floor(runif(10, 1880, 2020))) # Convert to the generations generations(yobs)
#> [1] Missionary Lost Lost G.I. Silent Boomer #> [7] Gen X Gen X Millennial Millennial #> Levels: Missionary Lost G.I. Silent Boomer Gen X Millennial
generations(yobs, full_names = TRUE)
#> [1] Missionary Generation Lost Generation Lost Generation #> [4] G.I. Generation Silent Generation Boomer Generation #> [7] Generation X Generation X Millennial Generation #> [10] Millennial Generation #> 7 Levels: Missionary Generation Lost Generation ... Millennial Generation
generations(yobs, full_names = TRUE, years = TRUE)
#> [1] Missionary Generation (1865–1885) Lost Generation (1886–1907) #> [3] Lost Generation (1886–1907) G.I. Generation (1908–1928) #> [5] Silent Generation (1929–1945) Boomer Generation (1946–1963) #> [7] Generation X (1964–1983) Generation X (1964–1983) #> [9] Millennial Generation (1984–2007) Millennial Generation (1984–2007) #> 7 Levels: Missionary Generation (1865–1885) ... Millennial Generation (1984–2007)
generations(yobs, years = TRUE, years_range_sep = " to ")
#> [1] Missionary (1865 to 1885) Lost (1886 to 1907) #> [3] Lost (1886 to 1907) G.I. (1908 to 1928) #> [5] Silent (1929 to 1945) Boomer (1946 to 1963) #> [7] Gen X (1964 to 1983) Gen X (1964 to 1983) #> [9] Millennial (1984 to 2007) Millennial (1984 to 2007) #> 7 Levels: Missionary (1865 to 1885) ... Millennial (1984 to 2007)