age_segment: Grouping by age segmentation

View source: R/aging.R

age_segmentR Documentation

Grouping by age segmentation

Description

The function allows to classify a group of subjects according their age_ A a vector of ages, is segmented finding the band containing each element.

Usage

age_segment(x, breaks, labels = NULL, factor = TRUE)

Arguments

x

Character vector of completed ages. Alternatively, a data matrix containing the same information. More levels of depth are allowed (see details).

breaks

Character vector specifying the lower limit of each age band. The intervals defining the bands are left-closed and right-opened. The last element of breaks represents the upper limit of the last band, which is excluded from the interval.

labels

Labels to assign to age bands.

factor

Logical. Should the resulting vector be a factor?

Details

The function requires an input vector expressing the completed age in character format, using the colon character : as separator. If the age units are years, the input age can be expressed as "years", "years:months" or "years:months:days", according to the level of depth. Similarly, if the age units are months, the input age can be expressed as "months" or "months:days".

The vector breaks reports the lower limits of each bands, except the last element, which reports the upper limit of the last band. For example, to define two bands, the first one including ages between 6:0:0 and 6:5:30, and the second one including ages between 6:6:0 and 6:11:30, you can define: breaks=c("6:0","6:6","7:0").

The function converts both x and breaks into numeric ages by using the function age_numeric and find the interval including each value in x.

See Also

age_numeric, cut, findInterval

Examples

age <- c("2:5","2:6","2:9","2:10","2:11","3:0","3:4",
    "3:5","3:6","3:7","3:11","3:11:30","4:0","4:1")
group <- age_segment(age,
    breaks=c("2:6","3:0","3:6","4:0"),
    labels=c("2:6-2:11","3:0-3:5","3:6-3:11")
)
data.frame(age,group)

DavideMassidda/testing documentation built on Oct. 12, 2023, 4:32 p.m.