View source: R/HelperFunctions.R
fillNAgaps | R Documentation |
NA
entries of a vector with the previous non-NA valueSometimes one has a vector with some gaps (NA
) values, which cause
problems for several numeric functions. This function fillNAgaps
fills
these missing values by inserting the last preceeding non-NA-value. Leading
NA values (at the start of the vector will not be modified). If the
argument firstBack = TRUE
, leading NA
-values are replaced by
the first non-NA value.
Trailing NAs are always replaced by the last previous NA-value.
fillNAgaps(x, firstBack = FALSE)
x |
The vector where NA-values should be filled by repeating the last preceeding non-NA value |
firstBack |
if |
This code was taken from the R Cookbook: http://www.cookbook-r.com/Manipulating_data/Filling_in_NAs_with_last_non-NA_value/ LICENSE (from that page): The R code is freely available for use without any restrictions. In other words: you may reuse the R code for any purpose (and under any license).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.