i_median_grp: Impute by group median

View source: R/impute.R

i_median_grpR Documentation

Impute by group median

Description

Replaces NAs in a numeric vector with the grouped medians of the non-NA values. Groups are defined by the f argument.

Usage

i_median_grp(x, f)

Arguments

x

A numeric vector

f

A grouping variable, of the same length of x, that specifies the group that each value of x belongs to. This will be coerced to a factor.

Value

A numeric vector

Examples

x <- c(NA, runif(10), NA)
f <- c(rep("a", 6), rep("b", 6))
i_median_grp(x, f)


COINr documentation built on Oct. 9, 2023, 5:07 p.m.