This function performs Last Observation Carried Forward (LOCF) imputation for missing values in a specified column (marker) of a dataset. The missing values are replaced by the last observed value before them in the dataset.

LOCF(dataset, marker)

Arguments

dataset

A data frame or tibble that contains the data. The dataset should have at least one column with missing values to apply LOCF imputation.

marker

The name (or index) of the column in the dataset where the missing values should be replaced with the last observed value.

Value

A data frame with the missing values in the `marker` column replaced by the last observed value before them.

Examples

data1 <- data.frame(id = 1:5, value = c(1, NA, 3, NA, 5))
LOCF(data1, "value")
#>   id value
#> 1  1     1
#> 2  2     1
#> 3  3     3
#> 4  4     3
#> 5  5     5