View source: R/filter_by_group_var.R
filter_by_group_var | R Documentation |
This function takes a data frame with two groups and splits them by a group identifier and specified column variables.
filter_by_group_var(df, grp_var, grp_1, grp_2, vars)
df |
A data frame which must have a column to identify two different groups. |
grp_var |
The column with the two groups, e.g., 'Treatment'. |
grp_1 |
The first group identifier in the |
grp_2 |
The second group identifier 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, group variable, and column variables are valid. It ensures that the specified groups exist within the group variable column. The function then filters the data for each group 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 group status.
# Load example data
data("group_data_example")
# Use the function to filter by group
result <- filter_by_group_var(df=group_data_example, grp_var="group",
grp_1 ='placebo',grp_2 ='drug',vars=c("v1", "v2"))
print(result$group_1)
print(result$group_2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.