is_category {madshapR} | R Documentation |
Test and validate if an object is a categorical variable.
Description
Tests if the input object is a categorical variable. This function mainly helps validate input within other functions of the package but could be used to check if a column is categorical.
Usage
is_category(x, threshold = NULL)
Arguments
x |
object to be coerced. |
threshold |
Optional. The function returns TRUE if the number of unique values in the input vector is lower. |
Value
A logical.
Examples
{
library(dplyr)
###### Example 1: use madshapR_examples provided by the package
dataset <-
madshapR_examples$`dataset_example` %>%
mutate(prg_ever_cat = as_category(prg_ever)) %>%
mutate(prg_ever_no_cat = drop_category(prg_ever))
is_category(dataset[['prg_ever_cat']])
is_category(dataset[['prg_ever_no_cat']])
###### Example 2: any data frame can be a dataset
iris %>% reframe(across(everything(), is_category))
}
[Package madshapR version 2.0.0 Index]