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
1 2 3 | categorical(x = logical(), levels = NULL,
alternatives = empty_alternatives(levels),
alternatives_internal = empty_alternatives(levels), class = c())
|
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 |
alternatives_internal |
a named list of vectors with alternative values corresponding to 'levels'. Must have the same length as levels. Can be accessed with |
class |
optional: name the subclass if you are using this to define a new vector type on top of the 'cat_categorical' class |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.