Learn R Programming

nmw (version 0.3.0)

merge_cov_locf: Merge Time-Varying Covariates by LOCF

Description

Merge time-varying covariate columns into a NM-style data.frame using LOCF (with LOCB for records before the first source). Subjects/records still NA after LOCF/LOCB can be filled with the column-wise median of cov_df.

Usage

merge_cov_locf(
  nm,
  cov_df,
  value_cols,
  time_col,
  median_fb = TRUE,
  verbose = FALSE,
  subj_col = "SUBJID",
  dat_col = "DAT2",
  tim_col = "TIME"
)

Value

nm with value_cols added.

Arguments

nm

data.frame with key columns subj_col, dat_col, tim_col.

cov_df

data.frame with subj_col, time_col, and one or more value columns.

value_cols

character vector of value columns in cov_df to bring into nm.

time_col

name of the time column in cov_df, parsed by parse_dtc.

median_fb

logical. If TRUE (default), fill remaining NA values with the column-wise median of cov_df.

verbose

logical. Print median fill counts. Default FALSE.

subj_col

subject ID column name. Default "SUBJID".

dat_col

date column name in nm. Default "DAT2".

tim_col

time column name in nm. Default "TIME".