CutAge | R Documentation |
Dividing the range of an age variable x
into intervals is a frequent task. The commonly used function cut
has unfavourable default values for this.
CutAge()
is a convenient wrapper for cutting age variables in groups
of e.g. 10 years with more suitable defaults.
CutGen
yields the generation of a person based on the year of birth.
CutAge(x, from = 0, to = 90, by = 10, right = FALSE, ordered_result = TRUE, ...)
CutGen(vintage)
x |
continuous variable. |
from , to |
the starting and (maximal) end values of the sequence. |
by |
number: increment of the sequence. Default is 10, alternatives could be 5 or 20. |
right |
logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa. Default is |
ordered_result |
logical: should the result be an ordered factor? Default is |
... |
the dots are passed on to the underlying function |
vintage |
year of birth |
The generations are defined as:
1946-1964 Babyboomer
1965-1979 Generation X
1980-1995 Generation Y – also known as Millennials
1996-2010 Generation Z
2011-.... Generation Alpha
A factor is returned, unless labels = FALSE which results in an integer vector of level codes.
Values which fall outside the range of breaks are coded as NA
, as are NaN
and NA
values.
Andri Signorell <andri@signorell.net>
cut
, seq
Desc(CutAge(sample(100, 100)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.