Learn R Programming

FastJM (version 1.7.0)

combine_biomarkers: Combine biomarker measurements across multiple data frames

Description

Combines specified biomarker measurements across a list of data frames and returns a unified long-format data set restricted to subjects with at least one recorded measurement for EVERY requested biomarker.

The function searches each provided data frame for the biomarker names listed in biomarkers, extracts the matching measurement rows, and standardizes the output into a common structure. Subjects are retained only if they have at least one non-missing measurement for every requested biomarker across the supplied data frames. It is intended for settings where biomarker measurements may be distributed across multiple data frames, and where each data frame may contain one or more of the requested biomarkers. The returned data are in long format so that repeated measurements per subject and per biomarker are preserved. No collapsing, averaging, or other within-subject summarization is performed.

Usage

combine_biomarkers(
  data_list,
  biomarkers,
  id_col,
  time_col = NULL,
  dataset_names = NULL
)

Value

A list with the following components:

combined_long

A long-format data frame containing only included subjects. The output includes the subject ID column, a dataset column identifying the source data frame, a biomarker column identifying the biomarker name, a standardized value column containing the measurement values, and a standardized time column if time_col was supplied.

included_ids

A vector of subject IDs retained in the final combined data. These are the subjects with at least one non-missing measurement for every requested biomarker.

ids_by_biomarker

A named list giving the subject IDs with at least one non-missing measurement for each biomarker.

presence_summary

A data frame summarizing biomarker presence among the included subjects, with one row per subject and one logical column per biomarker.

Arguments

data_list

A non-empty list of data frames containing subject-level biomarker measurements.

biomarkers

A character vector of biomarker column names to search for across the supplied data frames.

id_col

A character string giving the subject ID column name. This column must be present in every data frame in data_list.

time_col

An optional character string giving the time variable column name, such as days from baseline. If supplied, this column must be present in every data frame in data_list, and it is standardized to "time" in the returned long-format output.

dataset_names

An optional character vector of names for the supplied data frames. If omitted, the function uses names(data_list) when available; otherwise it creates default names of the form "dataset_1", "dataset_2", and so on.

Author

Shanpeng Li lishanpeng0913@ucla.edu

Examples

Run this code
df_a <- data.frame(
  ID = c(1, 1, 2, 3, 4, 5),
  day = c(0, 30, 0, 0, 0, 0),
  sbp = c(120, 125, 130, NA, 110, 118)
)

df_b <- data.frame(
  ID = c(1, 2, 2, 3, 5, 6),
  day = c(0, 0, 20, 0, 0, 0),
  dbp = c(80, 85, 84, 90, NA, 88)
)

df_c <- data.frame(
  ID = c(1, 1, 2, 4, 5, 5),
  day = c(0, 40, 0, 0, 0, 10),
  bpm = c(70, 72, 68, 75, 77, 79)
)

res <- combine_biomarkers(
  data_list = list(df_a, df_b, df_c),
  biomarkers = c("sbp", "dbp", "bpm"),
  id_col = "ID",
  time_col = "day"
)

res$included_ids
head(res$combined_long)
res$presence_summary

Run the code above in your browser using DataLab