Description Usage Arguments Details Value See Also Examples
View source: R/date_to_cohort.R
Assign dates to one-year cohorts.
1 | date_to_cohort_year(date, month_start = "Jan", label_year_start = TRUE)
|
date |
Dates of events defining cohorts (typically births).
A vector of class |
month_start |
An element of |
label_year_start |
Logical. Whether to label a cohort
by the calendar year at the beginning of the cohort
or the calendar year at the end. Defaults to |
Cohorts start on the first day of month_start
,
and end one-year-minus-one-day later.
The default value for month_start
is "Jan"
,
so cohorts by default start on 1 January and
end on 31 December. month_start
can be a
full month name or an abbreviation.
If a cohort starts on 1 January, then the first day and last day
of the cohort belong to the same calendar year.
But if a cohort starts on any other day, then
the first day belongs to one calendar
year and the last day belongs to the next calendar year.
For instance, if a cohort extends from
1 July 2000 to 30 June 2001, then the first
day belongs to calendar year 2000, and the last
day belongs to calendar year 2001. Some people
use the first calendar year to label such cohorts,
and others use the last calendar year.
For instance, if a cohort extends from
1 July 2000 to 30 June 2001, some people
label the cohort "2000"
, and
others label it "2001"
. Function
date_to_cohort_year
by default uses
the start year. To use the end year, set
label_year_start
to FALSE
.
An integer vector with the same length as date
.
The output from date_to_cohort_year
is ofen processed further using function
format_cohort_year
.
Other functions for creating
cohorts from dates are
date_to_cohort_quarter
and
and date_to_cohort_month
.
Other functions for creating one-year
intervals from dates are
date_to_age_year
,
date_to_period_year
,
and date_to_triangle_year
.
The interface for date_to_cohort_year
is identical
to that of date_to_period_year
.
1 2 3 4 5 6 7 8 9 10 11 | date_to_cohort_year(date = c("2024-03-27", "2022-11-09"))
## starts on 1 July rather than 1 January
date_to_cohort_year(date = c("2024-03-27", "2022-11-09"),
month_start = "Jul")
## periods starts on 1 July, rather than 1 January, and uses
## calendar year at end, rather than beginning, for the label
date_to_cohort_year(date = c("2024-03-27", "2022-11-09"),
month_start = "Jul",
label_year_start = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.