filter_by_time_var: Filter by Time Variable

View source: R/filter_by_time_var.R

filter_by_time_varR Documentation

Filter by Time Variable

Description

This function creates two groups based on their ID and separates them by a time variable. Each ID will be present in each subset exactly once. The subsets will contain the same variables specified by the user.

Usage

filter_by_time_var(df, id, time_var, pre, post, vars)

Arguments

df

A data frame which must have a column to identify two different groups by ID.

id

The column variable that will contain all of the IDs that show up twice in the data set.

time_var

The column variable that designates the time of the data, e.g., it may be a 0 if data was collected on the first day of treatment and a 6 if data is collected six days later.

pre

The value in the time_var column that indicates the 'pre' time point.

post

The value in the time_var column that indicates the 'post' time point.

vars

The column variables the researcher is interested in. The researcher can subset the columns instead of using all potential column variables.

Details

This function checks if the input data frame, ID, time variable, and column variablesare valid. It ensures that the specified pre and post values exist within the time variable column. The function then filters the data for each time point, orders the IDs, and returns a list containing the filtered data frames.

Value

A list of two data frames that are subsets of the original data frame, separated by their time_var status. The data frames will have the same size in rows.

Examples

# Load example data
data("pre_post_data_example")

# Use the function to filter by time variable
result <- filter_by_time_var(pre_post_data_example, id = "ID",
time_var = "time", pre = 0, post = 12, vars = c("v1", "v2"))
print(result$pre)
print(result$post)


PredTest documentation built on Sept. 16, 2024, 5:06 p.m.