Skip to contents

Get a subset of the data based on a specific term label in the categorical variables.

Usage

subsetByTermLabel(data, categorical_vars, term_label)

Arguments

data

The data frame to subset

categorical_vars

The categorical variables to consider

term_label

The term label to search for

Value

A subset of the data frame containing rows where the categorical variables match the specified term label

Examples

# Create a data frame
my_data <- data.frame(color = c("red", "blue", "green", "red"),
                      size = c("small", "medium", "large", "medium"),
                      shape = c("circle", "square", "triangle", "circle"))
my_data[] <- lapply(my_data, as.factor)

# Get the subset for the term "medium" in the "size" variable
subsetByTermLabel(my_data, "size", "medium")
#>   color   size  shape   term
#> 2  blue medium square medium
#> 4   red medium circle medium
# Output: A data frame with rows where "size" is "medium"

# Get the subset for the term "red" in the "color" variable
subsetByTermLabel(my_data, "color", "red")
#>   color   size  shape term
#> 1   red  small circle  red
#> 4   red medium circle  red
# Output: A data frame with rows where "color" is "red"