Learn R Programming

ksformat (version 0.3.5)

range_spec: Create Range Specification

Description

Helper function to create range specifications for numeric formats.

Usage

range_spec(low, high, label, inc_low = TRUE, inc_high = FALSE)

Value

A range_spec object (list with low, high, label, inc_low, inc_high).

Arguments

low

Numeric. Lower bound of the range.

high

Numeric. Upper bound of the range.

label

Character. Label for values in this range.

inc_low

Logical. If TRUE (default), the lower bound is inclusive (>=). If FALSE, exclusive (>).

inc_high

Logical. If TRUE, the upper bound is inclusive (<=). If FALSE (default), exclusive (<).

Details

By default, ranges are half-open: [low, high) — the lower bound is included and the upper bound is excluded. This matches 'SAS' PROC FORMAT range semantics and prevents overlap between adjacent ranges.

Examples

Run this code
range_spec(0, 18, "Child")          # [0, 18)
range_spec(18, 65, "Adult")         # [18, 65)
range_spec(65, Inf, "Senior", inc_high = TRUE)  # [65, Inf]

Run the code above in your browser using DataLab