imputeMean

0th

Percentile

imputeMean

Secondary function imputes the mean to columns with NA data.

Keywords
math, logic
Usage
impute.mean(x)
Arguments
x

a vector to calculate mean

Aliases
  • impute.mean
Examples
# NOT RUN {
library(fscaret)

# Make sample matrix
testData <- matrix(data=rep(1:5),ncol=10,nrow=15)

# Replace random values with NA's
n <- 15
replace <- TRUE
set.seed(1)

rand.sample <- sample(length(testData), n, replace=replace)
testData[rand.sample] <- NA 

# Print out input matrix
testData

# Record cols with missing values
missing.colsTestMatrix <- which(colSums(is.na(testData))>0)

for(i in 1:length(missing.colsTestMatrix)){

rowToReplace <- missing.colsTestMatrix[i]
testData[,rowToReplace] <- impute.mean(testData[,rowToReplace])

}

# Print out matrix with replaced NA's by column mean 
testData

# }
Documentation reproduced from package fscaret, version 0.9.4.4, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.