cut_ages | R Documentation |
cut_ages()
provides categorisation of ages based on specified breaks
which represent the left-hand interval limits. The resulting intervals span
from the minimum break through to a specified max_upper
and will always be
closed on the left and open on the right. Ages below the minimum break, or
above max_upper
will be returned as NA.
cut_ages(ages, breaks, max_upper = Inf)
ages |
Vector of age values. Double values are coerced to integer prior to categorisation / aggregation. Must not be NA. |
breaks |
1 or more non-negative cut points in increasing (strictly) order. These correspond to the left hand side of the desired intervals (e.g. the closed side of [x, y). Double values are coerced to integer prior to categorisation. |
max_upper |
Represents the maximum upper bound for the resulting intervals. Double values are rounded up to the nearest (numeric) integer. Defaults to |
A data frame with an ordered factor column (interval
), as well as columns
corresponding to the explicit bounds (lower
and upper
).
Internally both bound columns are stored as double but it can be taken as
part of the function API that lower
is coercible to integer without
any coercion to NA_integer_
. Similarly all values of upper
apart
from those corresponding to max_upper
can be assumed coercible to integer
(max_upper
may or may not depending on the given argument).
cut_ages(ages = 0:9, breaks = c(0, 3, 5, 10))
cut_ages(ages = 0:9, breaks = c(0, 5))
# Note the following is comparable to a call to
# cut(ages, right = FALSE, breaks = c(breaks, Inf))
ages <- seq.int(from = 0, by = 10, length.out = 10)
breaks <- c(0, 1, 10, 30)
cut_ages(ages, breaks)
# values above max_upper treated as NA
cut_ages(ages = 0:10, breaks = c(0,5), max_upper = 7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.