Select subjects that have at least a minimum number of visits and have occurrences at each instance of the time column. Optionally, return only subjects where the time column equals a user-specified baseline value.
select_longitudinal_subjects(
dataframe,
subjectID_column,
time_column,
min_visits,
baseline = NULL
)
The input dataframe.
The column name of the subject IDs.
The column name of the time variable.
The minimum number of visits required.
Optional baseline value to filter by. If specified, only subjects with a time column value equal to this baseline will be returned.
A dataframe containing the selected subjects.
dataframe <- data.frame(
subject_id = c(1, 1, 1, 2, 2, 3, 3, 3),
time = c(0, 1, 2, 0, 1, 0, 1, 2),
value = rnorm(8)
)
# Select subjects with at least 3 visits and occurrences at each time point
selected_subjects <- select_longitudinal_subjects(dataframe, "subject_id", "time", 3)
# Select subjects with at least 2 visits and occurrences at each time point,
# and return only subjects with a time column value equal to 0
selected_subjects <- select_longitudinal_subjects(dataframe, "subject_id", "time", 2, baseline = 0)