impute_missing_values | R Documentation |
impute_missing_values
is a function that takes a numeric vector with
missing data and replaces the NAs with the mean of the last value on the
left side and the first non-NA value on the right. It does this only for
repeated values of NA smaller than size max_na
. This means that if
max_na = 4
, the function will only replace missing values if there
are four or fewer missing values between the last non NA on the left and
the first non NA on the right.
impute_missing_values(data, max_na = 4)
data |
Numeric vector with missing data |
max_na |
Maximum number of NA in a row and still fill in values |
Numeric vector with NA values in groups <= max_na filled in
## Not run:
x <-
c(1, 1, NA, NA, NA, NA, 2, 2, 5, NA, NA, 6, 7, NA, 8, 9, NA,
NA, NA, NA, NA, 10, 10, 13, NA, NA, 14, NA, NA, NA, NA, NA, NA, NA, 12)
impute_missing_values(data = x)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.