format_triangle_year: Format labels for one-year Lexis triangles

Description Usage Arguments Details Value See Also Examples

View source: R/format_triangle.R

Description

Format labels for one-year Lexis triangles to be used with one-year age groups and periods.

Usage

1
format_triangle_year(x, age, break_max = 100, open_last = TRUE)

Arguments

x

A vector of Lexis triangle labels.

age

A vector of age groups, the same length as x.

break_max

An integer or NULL. Defaults to 100.

open_last

Whether the final age group has no upper limit. Defaults to TRUE.

Details

age gives the age group to which each triangle in x belongs. All age groups in age must be single-year, except for any open age groups.

open_last determines whether the allocation of triangles needs to account for an open age group, and break_max specifies the cut-off for the open age group. See format_age_year for a description of how open_last and break_max control age groups.

When break_max is NULL, the return value from format_triangle_year is identical to x. When break_max is non-NULL, the return value is as follows.

x age return value
"Lower" <= break_max "Lower"
"Lower" > break_max "Upper"
"Lower" NA NA
"Upper" <= break_max "Upper"
"Upper" > break_max "Upper"
"Upper" NA "Upper"
NA <= break_max NA
NA > break_max "Upper"
NA NA NA

Value

A factor with the same length as x.

See Also

Other functions for reformating triangle labels are format_triangle_multi, format_triangle_births, format_triangle_quarter, and format_triangle_month.

date_to_triangle_year creates one-year Lexis triangles from dates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## we construct 'x' and 'age' from
## dates information ourselves before
## calling 'format_triangle_year'
date_original <- c("2024-03-27", "2022-11-09")
dob_original <- "2020-01-01"
x <- date_to_triangle_year(date = date_original,
                           dob = dob_original,
                           month_start = "Jul")
age <- date_to_age_year(date = date_original,
                        dob = dob_original)
format_triangle_year(x = x,
                     age = age)

## someone else has constructed
## 'x' and 'age' from
## dates information
x_processed <- c("Lower", "Lower", "Lower")
age_processed <- c("10", "15", "5")
format_triangle_year(x = x_processed,
                     age = age_processed)

## alternative value for 'break_max'
format_triangle_year(x = x_processed,
                     age = age_processed,
                     break_max = 10)

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