Constructors and methods for a count data type. v_count and cnt are synonyms that each create a new v_count object subclassed from vctrs_vctr.

Support: $$\mathbf{N^+}$$* (plus NA_integer_)
Prototype: integer
* - i.e. the natural numbers including 0

v_count(
x = ptypeFUN(),
internal_name = "",
context,
auto_compute_summary = auto_compute_default,
extra_descriptors = list()
)

cnt(
x = ptypeFUN(),
internal_name = "",
context,
auto_compute_summary = auto_compute_default,
extra_descriptors = list()
)

is_count(x)

as_count(x)

# S3 method for v_count
as.character(x, ...)

as_canonical(x)

# S3 method for v_count
as_canonical(x)

## Arguments

x

a logical vector or any vector that can be cast to a logical vector via vctrs::vec_cast() such as integer or numeric vectors with values in {0, 1}.

internal_name

the internal name of the variable

context

a context

auto_compute_summary

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.

extra_descriptors

A list of descriptors functions appended to the default descriptors.

...

passed to other methods such as as.character

Other stype types: tbl_analysis, v_binary, v_continuous_nonneg, v_continuous, v_nominal, v_ordered, v_proportion, v_rcensored

## Examples

# Example data
src_count <- seq_len(5L)

# Constructor for the v_count class. One can also use cnt which is a
# synonym for the v_count function.
v <- v_count(
x = src_count,
internal_name = "v_example",
context = context(
short_label = "important_var",
long_label  = "Very important variable"
),
extra_descriptors = list()
)

# Helper functions and methods
is_count(v)
#> [1] TRUE
as_count(src_count)
#> <count[5]>
#> [1] 1 2 3 4 5
#> Total = 15; Mean = 3.000
as.character(v)
#> [1] "1" "2" "3" "4" "5"
as_canonical(v)
#> [1] 1 2 3 4 5