get_fct_lvls: Get factor levels for a variable. Unique ones only or all of...

View source: R/get_fct_lvls.R

get_fct_lvlsR Documentation

Get factor levels for a variable. Unique ones only or all of te

Description

Given a data frame and a column, the function will return the factor levels. If unique_lvls = TRUE, then it will only return the levels for which there is a value in the data.

Usage

get_fct_lvls(data, x, unique_lvls = TRUE)

Arguments

data

A data frame or tibble

x

Column in the data

unique_lvls

Logical. If TRUE (default), then only the possible values of a factor are returned. If FALSE, then the original factor levels are returned.

Value

A character vector or NULL

References

/urlhttps://chemicalstatistician.wordpress.com/2018/03/10/use-unique-instead-of-levels-to-find-the-possible-values-of-a-character-variable-in-r/

Examples

get_fct_lvls(data = iris, x = Species)

iris2 <- subset(iris, Species != "setosa")
table(iris2$Species)
get_fct_lvls(data = iris2, x = Species)
get_fct_lvls(data = iris2, x = Species, unique_lvls = FALSE)

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.