major: Majority imputation for a vector

Description Usage Arguments Value Examples

View source: R/funs.R

Description

This function is internally used by guess, it may be useless in reality.

Usage

1
major(x)

Arguments

x

a character (or numeric categorical) vector with missing values

Value

the same length of vector with missing values being imputed by the majority class in this vector.

Examples

1
2
3
4
5
a <- c(rep(0, 10), rep(1, 15), rep(2, 5))
a[sample(seq_along(a), 5)] <- NA
a
b <- major(a)
b

Example output

 [1] NA  0  0  0  0  0 NA  0  0  0  1  1  1  1  1  1  1  1  1  1  1 NA  1  1  1
[26]  2 NA NA  2  2
 [1] "1" "0" "0" "0" "0" "0" "1" "0" "0" "0" "1" "1" "1" "1" "1" "1" "1" "1" "1"
[20] "1" "1" "1" "1" "1" "1" "2" "1" "1" "2" "2"

imputeR documentation built on Jan. 21, 2020, 1:06 a.m.