Learn R Programming

fast (version 0.64)

na2mean: Replace NA in a vector by mean of neighboring values.

Description

This method replaces NA-Values in a vector by the mean of the neighboring values. Example: c(1,NA,3) is converted to c(1,2,3).

Usage

na2mean(x)

Arguments

x
Vector to fill

Value

Vector with NA replaced by mean.

Details

The method does not work if multiple NA are in sequence.

Examples

Run this code
na2mean(c(1,NA,2))
na2mean(c(1,NA,NA,2))

Run the code above in your browser using DataLab