replace_na: Replace NA values

Description Usage Arguments Value Examples

Description

Replaces NA values with a defined alternative. For a numeric vector, this can be either the mean or median of the vector. For a character or factor vector, this will be the mode.

Usage

1
replace_na(x, method)

Arguments

x

Vector that contains NA values.

method

Replacement method for NA values. For a numeric vector the user can choose between 'mean' and 'median'. For character or factor vectors the mode is automatically chosen.

Value

A vector without NA values.

Examples

1
2
3
4
5
6
7
x <- c(1, 3, 5, 5, 6, NA, 10)
replace_na(x)
# 1  3  5  5  6  5 10

x <- c("Cat", "Dog", "Catdog", NA, "Cat")
replace_na(x)
# "Cat"    "Dog"    "Catdog" "Cat"    "Cat"

camroach87/myhelpr documentation built on May 13, 2019, 11:03 a.m.