Adds base value to a long-format data frame.
Arguments
- data
data frame in long format.
- var
A named character vector with the variable name to use. The name of the character vector should match the column in the data frame with the variable names.
- event
A names character vector with the event that identifies the baseline value. The name of the character vector should match the column in the data frame with the event names.
- value_column
A string containing the column name with the item values.
- id_column
The columns identifying a unique participant (subject_id).
Examples
library(dplyr)
library(tidyr)
# create a long time series data frame:
df <- as.data.frame(EuStockMarkets) |>
mutate(time = time(EuStockMarkets)) |>
pivot_longer(-time)
output <- get_base_value(df, c("name" = "DAX"), event = c("time" = df$time[1]),
value_column = "value", id_column = NULL)