This function checks if a given variable is categorical. A variable is considered categorical if it is a factor, a character, or a logical type. Additionally, numeric variables with a small number of unique values (less than a specified threshold) are also considered categorical.
Arguments
- x
The variable to be tested for being categorical.
Value
A logical value indicating whether the input variable is categorical (TRUE) or not (FALSE).
Examples
is_categorical(factor(c("A", "B", "C")))
#> [1] TRUE
is_categorical(c("A", "B", "C"))
#> [1] TRUE
is_categorical(c(TRUE, FALSE))
#> [1] TRUE
is_categorical(c(1, 2, 3, 4))
#> [1] TRUE
is_categorical(c(1.2, 3.5, 4.6, 7.8))
#> [1] TRUE