"na.omit"(object, method = c("r", "s", "z", "ir", "iz", "ie"), interp = c("before", "linear", "after"), ...)removeNA(x, ...) substituteNA(x, type = c("zeros", "mean", "median"), ...) interpNA(x, method = c("linear", "before", "after"), ...)
type="zeros"replaces the missing values by zeros,
type="mean"replaces the missing values by the column mean,
type="median"replaces the missing values by the the column median.
method="s"na.rm = FALSE, skip, i.e. do nothing,
method="z"substitute NAs by zeros,
method="ir"interpolate NAs and remove NAs at the beginning and end of the series,
method="iz"interpolate NAs and substitute NAs at the beginning and end of the series,
method="ie"interpolate NAs and extrapolate NAs at the beginning and end of the series, [interpNA] - Specifies the method how to interpolate the matrix column by column. One of the applied vector strings:
method="after". For the interpolation the function
x = as.matrix(x, ...). If
xis a vector, it will be transformed into a one-dimensional matrix.
Functions for handling missing values in 'timeSeries' objects and in objects which can be transformed into a vector or a two dimensional matrix. The functions are listed by topic.
|Removes NAs from a matrix object,|
|substitute NAs by zero, the column mean or median,|
Missing Values in Price and Index Series:
timeSeries objects the function
just removes rows with NAs from the series. For an interpolation
of time series points one can use the function
Three different methods of interpolation are offered:
does a linear interpolation,
"before" uses the previous value,
"after" uses the following value. Note, that the
interpolation is done on the index scale and not on the time scale.
Missing Values in Return Series:
For return series the function
substituteNA may be useful. The
function allows to fill missing values either by
method="mean" or the
method="median" value of the
Troyanskaya O., Cantor M., Sherlock G., Brown P., Hastie T., Tibshirani R., Botstein D., Altman R.B., (2001); Missing Value Estimation Methods for DNA microarrays Bioinformatics 17, 520--525.
## Create a Matrix - X <- matrix(rnorm(100), ncol = 5) ## Replace a Single NA Inside - X[3, 5] <- NA ## Replace Three in a Row Inside - X[17, 2:4] <- c(NA, NA, NA) ## Replace Three in a Column Inside - X[13:15, 4] <- c(NA, NA, NA) ## Replace Two at the Right Border - X[11:12, 5] <- c(NA, NA) ## Replace One in the Lower Left Corner - X[20, 1] <- NA print(X) ## Remove Rows with NAs - removeNA(X) ## Subsitute NA's by Zeros or Column Means - substituteNA(X, type = "zeros") substituteNA(X, type = "mean") ## Interpolate NA's Linearily - interpNA(X, method = "linear") # Note the corner missing value cannot be interpolated! ## Take Previous Values in a Column - interpNA(X, method = "before") # Also here, the corner value is excluded