imputeTS (version 2.6)

na.random: Missing Value Imputation by Random Sample

Description

Replaces each missing value by drawing a random sample between two given bounds.

Usage

na.random(x, lowerBound = min(x, na.rm = TRUE), upperBound = max(x, na.rm =
  TRUE))

Arguments

x

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

lowerBound

Lower bound for the random samples (default is min(data) )

upperBound

Upper bound for the random samples (default is max(data) )

Value

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

Details

Replaces each missing value by drawing a random sample between two given bounds. The default bounds are the minimum and the maximum value in the non-NAs from the time series. Function uses runif function to get the random values.

See Also

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

Examples

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

#Example 1: Replace all NAs by random values that are between min and max of the input time series
na.random(x)

#Example 2: Replace all NAs by random values between 1 and 10
na.random(x, lowerBound = 1, upperBound = 10)

# }

Run the code above in your browser using DataCamp Workspace