Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fmt_range

Formatted Range


Description

A function to calculate and format a numeric range.

Usage

fmt_range(x, format = "%s", sep = "-")

Arguments

x

The input data vector or data frame column.

format

A formatting string suitable for input into the sprintf function. By default, this format is defined as "%s", which simply converts the value to a string with no specific formatting.

sep

The token used to separate the minimum and maximum range values. Default value is a hyphen ("-").

Details

This function calculates a range using the Base R range function, and then formats the output using sprintf. You may control the format using the format parameter. Any NA values in the input data are ignored. Results are returned as a character vector.

Value

The formatted range values.

See Also

Examples

# Create example vector
v1 <- c(4.3, 3.7, 8.7, 6.1, 9.2, 5.6, NA, 0.7, 7.8, 4.9)

# Format range
fmt_range(v1)

# Output
# "0.7 - 9.2"

fmtr

Easily Apply Formats to Data

v1.5.0
CC0
Authors
David Bosak
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.