Learn R Programming

OLCPM (version 0.1.1)

impute.linear: impute missing entries by linear interpolation

Description

This function imputes missing entries in a numeric vector by linear interpolation.

Usage

impute.linear(x)

Value

a new numeric vector, with the same size of the original vector, while all the missing entries have been imputed.

Arguments

x

a numeric data vector, where \(NA\) indicates missing entries. The vector should contain at least two non-missing values.

Author

Yong He, Xinbing Kong, Lorenzo Trapani, Long Yu

Details

A missing entry will be imputed by linear interpolation with the two nearest values before and after it in the vector. When all the values before (after) it are missing, use the two nearest values after (before) it, instead.

Examples

Run this code

a=c(NA,NA,3,NA,NA,6,NA,NA)
b=c(1,2,3,4.5,5,NA,6.5,7,NA)

impute.linear(a)
impute.linear(b)

Run the code above in your browser using DataLab