Skip to contents

This function separates baseline data in a data frame by separating baseline and non-baseline records.

Usage

separate_baseline_df(
  df,
  time_var = "Time",
  baseline_lvl = "Baseline",
  var_name = "Outcome",
  id_vars = c("PartId", "Group")
)

Arguments

df

A data frame containing the data.

time_var

A string specifying the name of the time variable (default is "Time").

baseline_lvl

A string specifying the baseline level (default is "Baseline").

var_name

A string specifying the name of the outcome variable (default is "Outcome").

id_vars

A character vector of identifier variables (default is c("PartId", "Group")).

Value

A data frame that includes the non-baseline records and adds a column for the baseline outcome.

Examples

df <- data.frame(
  PartId = c(1, 1, 2, 2),
  Group = c("A", "A", "B", "B"),
  Time = c("Baseline", "Post", "Baseline", "Post"),
  Outcome = c(10, 12, 20, 22)
)

result <- separate_baseline_df(df)
print(result)
#>   PartId Group Time Outcome OutcomePre
#> 1      1     A Post      12         10
#> 2      2     B Post      22         20