View source: R/filter_by_time_var.R
filter_by_time_var | R Documentation |
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.
filter_by_time_var(df, id, time_var, pre, post, vars)
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 |
post |
The value in the |
vars |
The column variables the researcher is interested in. The researcher can subset the columns instead of using all potential column variables. |
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.
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.