handle missing values in objects

Description

use these functions as argument to functions that require you specify a 'na.action'.

na.fill returns the object, where all NA are replaced with observations from the object. all observed values are carried forward and the first is carried backward. cfr na.locf from zoo library.

na.zero returns the object, where all NA are replaced with zeroes.

na.interpolate fills in the gaps linearly interpolating between the last preceding and first following observations. if the gaps are at the head or tail of the vector, they are filled in as constants.

these are not generic functions: the object must be a vector (a data.frame is a vector, too).

Usage

1
2
3
na.fill(object)
na.zero(object)
na.interpolate(object)

Arguments

object

the vector, possibly containing NA values.

Examples

1
2
3
na.fill(c(1,2,3,NA))  # propagates the 3 forward
na.fill(c(NA,2,3,4))  # propagates the 2 backward
na.fill(c(NA,2,NA,NA))  # propagates the 2 backward and forward