impute: Impute missing values with the mean/median/mode or 'impute'

Description Usage Arguments Details Value Examples

Description

When the mean/median/mode method is used: character vectors and factors are imputed with the mode.

Usage

1
impute(data, method = "methods")

Arguments

data

A data frame with factor or numeric variables. When columns are of type "character", method=="mode" .

method

Either "mean/median/mode". Only works if object = NULL, that is missing , NA

Details

Numeric and integer vectors are imputed with the mean/median.For imputing missing values the function is impute.

Value

An imputed dataframe data with method selected by user

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#Dummy dataset
dat <- data.frame(x=sample(letters[1:3],20,TRUE), 
                  y=sample(letters[1:3],20,TRUE),
                  w=rnorm(20),
                  z=sample(letters[1:3],20,TRUE), 
                  b = as.logical(sample(0:1,20,TRUE)),
                  stringsAsFactors=FALSE)

dat[c(5,10,15),1] <- NA
dat[c(3,7),2] <- NA
dat[c(1,3,5),3] <- NA
dat[c(4,5,9),4] <- NA
dat[c(4,5,9),5] <- NA
dat[,4] <- factor(dat[,4] )
#Usage
impute(dat,method = "mean")

UBC-MDS/tidyplusR documentation built on May 25, 2019, 1:36 p.m.