groupAges: groupAges

View source: R/groupAges.R

groupAgesR Documentation

groupAges

Description

Helper function to bin a vector of continuous ages into groups and automatically generate labels.

Usage

groupAges(
  x,
  lower,
  upper,
  by,
  sep = " - ",
  include.below = TRUE,
  include.above = TRUE,
  below.char = "<",
  above.char = "+"
)

Arguments

x

Vector to be grouped (usually ages in years)

lower

Lower bound (inclusive) of age

upper

Upper bound (exclusive) of age

by

How many years to group by

sep

Controls the serperator in the label between the the lower and upper bound for each age group

include.below

If TRUE (default) value under the lower bound will be included and labeled accordingly. If false, values under will be returned as NA

include.above

If TRUE (default) value over the upper bound will be included and labeled accordingly. If false, values over will be returned as NA

below.char

The character to use for labeling the group of value under the lower bound

above.char

The character to use for labeling the group of value above the lower bound

Value

Returns a factor vector of the same length as x.

Author(s)

Matthew Phelps <mphelps@hjerteforeningen.dk>

Examples

library(heaven)
set.seed(1)
x <- floor(runif(20, min = 0, max = 105))
groupAges(
 x,
 lower = 15,
 upper = 50,
 by = 10,
 below.char = "<",
 above.char = "+"
)

tagteam/heaven documentation built on April 26, 2024, 6:22 a.m.