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
)

Arguments

dataframe

The input dataframe.

subjectID_column

The column name of the subject IDs.

time_column

The column name of the time variable.

min_visits

The minimum number of visits required.

baseline

Optional baseline value to filter by. If specified, only subjects with a time column value equal to this baseline will be returned.

Value

A dataframe containing the selected subjects.

Examples

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)