## SOURCE("fMultivar.C2-MissingValues")
## Create a Matrix with NAs:
X = matrix(rnorm(100), ncol = 5)
# a single NA inside:
X[3, 5] = NA
# three in a row inside:
X[17, 2:4] = c(NA, NA, NA)
# three in a column inside:
X[13:15, 4] = c(NA, NA, NA)
# two at the right border:
X[11:12, 5] = c(NA, NA)
# one in the lower left corner:
X[20, 1] = NA
print(X)
## Remove rows with NA's
removeNA(X)
# Now we have only 12 lines!
## Subsitute NA's by zeros or column mean
substituteNA(X, type = "zeros")
substituteNA(X, type = "mean")
## Interpolate NA's liearily:
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
## Interpolate using the knn Algorithm:
knnNA(X)Run the code above in your browser using DataLab