split_at_median: Dichotomize vector values at their median

View source: R/split_at_median.R

split_at_medianR Documentation

Dichotomize vector values at their median

Description

Dichotomize vector values at their median

Usage

split_at_median(
  x,
  labels = c("low", "high"),
  type = "higher",
  explicit_na = NA
)

Arguments

x

A vector

type

"higher" will split group at above median (vs. equal and below) and "lower" will split group below median (vs. equal and above)

explicit_na

If not NA, NAs will be recoded as a factor level of the provided name. If TRUE, the name will default to '(Missing)'.

lab

Vector with two factor labels.

Value

A vector of type factor with two levels.

Examples

x <- sample(c(1:10, NA), 100, replace = TRUE)
x <- split_at_median(x, explicit_na = TRUE)
table(x)


jazznbass/wmisc documentation built on Oct. 29, 2024, 5:42 p.m.