q.locf: LOCF Imputation

View source: R/q.locf.R

q.locfR Documentation

LOCF Imputation

Description

Perform "last observation carried forward" imputation on a dataset. If the first measurement is missing, the function also performs "first observation carried backward" imputation.

Usage

q.locf(db, sliceby=c())

Arguments

db

Data frame with missing values

sliceby

Fields by which the data should be split before imputation. This ensures that each imputation is only based on the same subject's data

Value

A data frame

Note

Dataset needs to be ordered by subject ID and time, and any other characteristics. This ensures that only the previous measurement is used for imputation.

Author(s)

Abdul Malik Sulley <asulley@uwo.ca> April 5, 2020

See Also

zoo::na.locf

Examples

mybeaver <- beaver1
#order by day and time
mybeaver <- mybeaver[order(mybeaver$day, mybeaver$time),] 
#make some data missing
mybeaver$temp[c(6, 10, 22, 55, 57)] <- NA
q.locf(mybeaver, sliceby="day")

qwickmalik/qwickr documentation built on March 30, 2022, 2:59 p.m.