v_binary: Binary vectors

v_binaryR Documentation

Binary vectors

Description

Constructors and methods for a binary data type. v_binary and bnry are synonyms that each create a new v_binary object subclassed from vctrs_vctr.

Support: \{0, 1\} (plus NA)
Prototype: logical

Usage

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

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

is_binary(x)

as_binary(x)

## S3 method for class 'v_binary'
as.character(x, ...)

## S3 method for class 'v_binary'
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

See Also

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

Examples

# Example data
src_binary <- c(TRUE, FALSE, TRUE, FALSE, NA)

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

# Helper functions and methods
is_binary(v)
as_binary(src_binary)
as.character(v)
as_canonical(v)

novisci/stype documentation built on July 28, 2022, 7:44 a.m.