date_to_triangle_year: Convert dates to one-year Lexis triangles

Description Usage Arguments Details Value See Also Examples

View source: R/date_to_triangle.R

Description

Use dates of events and dates of birth to create one-year Lexis triangles.

Usage

1
date_to_triangle_year(date, dob, month_start = "Jan")

Arguments

date

Dates of events. A vector of class Date, or a vector that can be coerced to class Date using function as.Date.

dob

Dates of birth. A vector of class Date, or a vector that can be coerced to class Date using function as.Date.

month_start

An element of month.name, or month.abb. The period starts on the first day of this month.

Details

See vignette("demprep") for the definition of Lexis triangles.

date and dob must have the same length, unless one of them has length 1, in which case the length-1 argument is recycled.

Periods 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 periods by default start on 1 January and end on 31 December.

Value

A character vector with the same length as date.

See Also

The output from date_to_triangle_year is often processed further using function format_triangle_year.

Other functions for creating triangles from dates are date_to_triangle_quarter and date_to_triangle_month.

Other functions for creating one-year units from dates are date_to_age_year. date_to_period_year, and date_to_cohort_year.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
date_to_triangle_year(date = c("2024-03-27",
                               "2022-11-09"),
                      dob = "2020-01-01")

## starts on 1 July rather than 1 January
date_to_triangle_year(date = c("2024-03-27",
                               "2022-11-09"),
                      dob = "2020-01-01",
                      month_start = "Jul")

## events occurring to people born during the
## period in question are always allocated to
## lower Lexis triangles
date_to_triangle_year(date = c("2020-03-19",
                               "2020-06-18"),
                      dob = c("2020-03-01",
                              "2020-06-18"))

johnrbryant/demprep documentation built on Dec. 31, 2021, 11:58 a.m.