groupAges | R Documentation |
Helper function to bin a vector of continuous ages into groups and automatically generate labels.
groupAges(
x,
lower,
upper,
by,
sep = " - ",
include.below = TRUE,
include.above = TRUE,
below.char = "<",
above.char = "+"
)
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 |
Returns a factor vector of the same length as x.
Matthew Phelps <mphelps@hjerteforeningen.dk>
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 = "+"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.