fillNAgaps {LifeInsureR}R Documentation

Replace all NA entries of a vector with the previous non-NA value

Description

Sometimes 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.

Usage

fillNAgaps(x, firstBack = FALSE)

Arguments

x

The vector where NA-values should be filled by repeating the last preceeding non-NA value

firstBack

if TRUE, leading NAs are replaced by the first non-NA value in the vector, otherwise leading NAs are left untouched.

Details

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).

Value

vector with NAs properly replaced


[Package LifeInsureR version 1.0.0 Index]