Constructors and methods for a nomimal categorical data type.
v_nominal and nom are synonyms that each create a new
v_nominal object subclassed from vctrs_vctr and factor.
Support: see factor
Prototype: integer
v_nominal(
x = factor(),
internal_name = "",
context,
auto_compute_summary = auto_compute_default,
extra_descriptors = list()
)
nom(
x = factor(),
internal_name = "",
context,
auto_compute_summary = auto_compute_default,
extra_descriptors = list()
)
is_nominal(x)
as_nominal(x)
# S3 method for v_nominal
as_canonical(x)a factor
the internal name of the variable
a context
an indicator of whether the data_summary is
automatically computed whenever a vector is initialized, subset, or
concatenated. Defaults to TRUE. If this option is set to FALSE,
then get_data_summary is the only way to compute the summary.
The data_summary_l lens will return an empty data_summary.
A list of descriptors functions
appended to the default descriptors.
Other stype types:
tbl_analysis,
v_binary,
v_continuous_nonneg,
v_continuous,
v_count,
v_ordered,
v_proportion,
v_rcensored
# Example data
src_fct <- factor(c("a", "bb", "a", "ccc", NA_character_))
# Constructor for the `v_nominal` class. One can also use `nom` which is a
# synonym for the `v_nominal` function.
v <- v_nominal(
x = src_fct,
internal_name = "v_example",
context = context(
short_label = "important_var",
long_label = "Very important variable"
),
extra_descriptors = list()
)
# Helper functions and methods
is_nominal(v)
#> [1] TRUE
as_nominal(src_fct)
#> <nominal[5]>
#> [1] a bb a ccc <NA>
#> Proportions: a: 40% bb: 20% ccc: 20% NA: 20%; Missing = 1
as.character(v)
#> [1] "a" "bb" "a" "ccc" NA
as_canonical(v)
#> [1] a bb a ccc <NA>
#> Levels: a bb ccc