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

fmt_median

Formatted Median


Description

A function to calculate and format a median.

Usage

fmt_median(x, format = "%.1f")

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 "%.1f", which displays the value with one decimal place.

Details

This function calculates a median using the stats package median function, and then formats the output using sprintf. You may control the format using the format parameter. Function will ignore any NA values in the input data. Results are returned as a character vector.

Value

The formatted median value.

See Also

Examples

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

# Format median
fmt_median(v1)

# Output
# "5.6"

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.