drop_fct_lvls: Drop factor levels and filter the data the same time

View source: R/drop-fct-lvls.R

drop_fct_lvlsR Documentation

Drop factor levels and filter the data the same time

Description

When you filter data to remove rows that match a level in a factor, the factor levels aren't removed. This function will filter the data and drop the factor levels.

Usage

drop_fct_lvls(data, x, lvls)

Arguments

data

A data frame or tibble

x

A factor (or character vector).

lvls

Character string of factor levels to drop

Value

An object of the same type as data.

Examples

library(dplyr)
library(palmerpenguins)

penguins %>%
  dplyr::count(species)

penguins %>%
  drop_fct_lvls(data = .,
                x = species,
                lvls = c("Chinstrap")) %>%
  dplyr::count(species)

penguins %>%
  drop_fct_lvls(data = .,
                x = species,
                lvls = c("Chinstrap",
                         "Gentoo")) %>%
  dplyr::count(species)

emilelatour/lamisc documentation built on May 10, 2024, 8:38 a.m.