imputeTS (version 2.7)

na.mean: Missing Value Imputation by Mean Value

Description

Missing value replacement by mean values. Different means like median, mean, mode possible.

Usage

na.mean(x, option = "mean")

Arguments

x

Numeric Vector (vector) or Time Series (ts) object in which missing values shall be replaced

option

Algorithm to be used. Accepts the following input:

  • "mean" - take the mean for imputation

  • "median" - take the median for imputation

  • "mode" - take the mode for imputation

Value

Vector (vector) or Time Series (ts) object (dependent on given input at parameter x)

Details

Missing values get replaced by overall mean values. The function calculates the mean, median or mode over all the non-NA values and replaces all NAs with this value. Option 'mode' replaces NAs with the most frequent value in the time series. If two or more values occur equally frequent, the function imputes with the lower value. That's why 'mode' is not the best option for decimal values.

See Also

na.interpolation, na.kalman, na.locf, na.ma, na.random, na.replace, na.seadec, na.seasplit

Examples

# NOT RUN {
#Prerequisite: Create Time series with missing values
x <- ts(c(2,3,4,5,6,NA,7,8))

#Example 1: Perform imputation with the overall mean
na.mean(x)

#Example 2: Perform imputation with overall median
na.mean(x, option ="median")

#Example 3: Same as example 1, just written with pipe operator
x %>% na.mean

# }