powered by
Returns a vector with the length equal to the number of rows in the data with the baseline value of the var repeated for every time value of each id.
data
var
time
id
repeat_baseline_values(data, var, id, time, baseline_level, repeat_NA = TRUE)
A vector of the same lenght and class of var.
A data frame.
The bare (unquoted) name of the column with the values to be repeated.
The bare (unquoted) name of the column that identifies each subject.
The bare (unquoted) name of the column with the time values.
The value of time corresponding the baseline.
A logical vector indicating whether or not NA values in the var will correspond to NA values in return vector. Defaults to TRUE.
NA
TRUE
df <- data.frame( id = rep(1:5, each = 4), time = rep(1:4, 5), score = rnorm(20, mean = 10, sd = 2) ) df$baseline_score <- repeat_baseline_values(df, score, id, time, 1) df
Run the code above in your browser using DataLab