fmap_ranges: Build a Vector of Range Mappings

View source: R/utilities.R

fmap_rangesR Documentation

Build a Vector of Range Mappings

Description

Construct a ks_fmap-classed named character vector whose names encode numeric / Date / POSIXct range bounds and whose values are the corresponding labels. The result is intended to be passed to fnew as a single positional argument (it suppresses the default name reversal).

Usage

fmap_ranges(
  low,
  high,
  label,
  inc_low = TRUE,
  inc_high = FALSE,
  date_format = NULL
)

Arguments

low, high

Numeric, Date, or POSIXct vectors of equal length giving the lower / upper bounds of each range.

label

Character vector of labels (same length as low).

inc_low, inc_high

Logical, length 1 or length(low). Whether each bound is inclusive. Defaults match range_spec: [low, high).

date_format

Optional strptime format string used when formatting Date/POSIXct bounds into key strings.

Details

Bounds are formatted as ISO 8601: "%Y-%m-%d" for Date, "%Y-%m-%d %H:%M:%S" (UTC) for POSIXct. Override with date_format if needed.

Value

A ks_fmap object (named character vector) suitable for passing to fnew().

See Also

fmap, fmap_strata, fnew

Examples

rng <- fmap_ranges(
  low   = c(0, 18, 65),
  high  = c(18, 65, Inf),
  label = c("Child", "Adult", "Senior"),
  inc_high = c(FALSE, FALSE, TRUE)
)
fnew(rng, type = "numeric", name = "age_groups")
fput(c(5, 25, 90), "age_groups")
fclear()

ksformat documentation built on May 21, 2026, 9:07 a.m.