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 )
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 |
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)". |
years_sep | a string. If |
years_range_sep | a string. If |
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. |
a vector
Note that labels are included for years between 1435 and 2030. Anything outside
of that range will return NA
.
# 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 Millennialgenerations(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 Generationgenerations(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)