filter_cat: Filter data by levels of categorical variables

View source: R/filter.R

filter_catR Documentation

Filter data by levels of categorical variables

Description

This function filters a dataframe or survey design object by keeping only the rows where a specified categorical variable matches one of the given levels. The resulting filtered dataframe is returned, along with the tidyverse code used to generate it.

Usage

filter_cat(data, var, levels)

Arguments

data

A dataframe or survey design object to be filtered.

var

The name of the column in data to be filtered by.

levels

A character vector of levels in var to keep.

Value

A filtered dataframe with the tidyverse code attached.

Author(s)

Owen Jin, Zhaoming Su

See Also

code

Examples

filtered <- filter_cat(iris,
    var = "Species",
    levels = c("versicolor", "virginica")
)
cat(code(filtered))
head(filtered)


iNZightTools documentation built on Oct. 12, 2023, 5:06 p.m.