categorical: cat_categorical is the main vector class. It gives a general...

Description Usage Arguments

View source: R/00-00-cat.R

Description

cat_categorical is the main vector class. It gives a general structure from which the more specific categorical classes can be constructed. cat_categorical is: - a standard vctrs_vctr vctrs_rcrd (see vctrs package), with a logical vector for each level, indicating which levels were selected for each entry - the 'main' values are a character strings - it has a 'levels' attribute with a vector containing all unique categories - it has an attribute for _alternative values_, allowing the user to add different alternative values, such as labels in different languages - it has an attribute for _internal alternative values_ intended for use in specific subclasses. What these are depends on the specific sublass; for example these could be: - for an "interval" subclass: lower and upper limit - for an "ordinal" subclass: integer rank it follows the generic methods to create categorical() vectors from different data types. for most types, we - check if the inputs are valid - convert the input to a logical matrix - then use categorical.matrix(), which - checks that the inputs are still valid - converts inputs to what they should be like for the final attributes - call new_categorical() - which creates the final vector with vctrs::new_rcrd() create a new categorical variable

Usage

1
2
3

Arguments

x

a vector or list to be used as values for the categorical vector

levels

list of possible values for x; similar to factor levels

alternatives

a named list of vectors with alternative values corresponding to 'levels'. Must have the same length as levels. Can be accessed with alternate.

alternatives_internal

a named list of vectors with alternative values corresponding to 'levels'. Must have the same length as levels. Can be accessed with alternate. "internal" alternatives are used to store 'fixed' alternatives for classes extending 'cat_categorical'.

class

optional: name the subclass if you are using this to define a new vector type on top of the 'cat_categorical' class


mabafaba/categorical documentation built on May 3, 2020, 9 p.m.