filter_by_group_var: Filter by Group Variable

View source: R/filter_by_group_var.R

filter_by_group_varR Documentation

Filter by Group Variable

Description

This function takes a data frame with two groups and splits them by a group identifier and specified column variables.

Usage

filter_by_group_var(df, grp_var, grp_1, grp_2, vars)

Arguments

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_var column, e.g., 'control'.

grp_2

The second group identifier in the grp_var column, e.g., 'drug_a'.

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, 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.

Value

A list of two data frames that are subsets of the original data frame, separated by their group status.

Examples

# 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)


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