Constructors and methods for a continuous data type. v_continuous and cont are synonyms that each create a new v_continuous object subclassed from vctrs_vctr.

Support: \(\mathbf{R}\)* (plus NA_real_)
Prototype: double
* - i.e. floating-point number

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

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

is_continuous(x)

as_continuous(x)

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

# S3 method for v_continuous
as_canonical(x)

Arguments

x

a double vector

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

Examples

# Example data
src_dbl <- c(-0.5, 1, 2.5, 4, 5.5, NA_real_)

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

# Helper functions and methods
is_continuous(v)
#> [1] TRUE
as_continuous(src_dbl)
#> <continuous[6]>
#> [1] -0.5 1    2.5  4    5.5  <NA>
#> Mean = 2.500; SD = 2.372; Missing = 1
as.character(v)
#> [1] "-0.5" "1"    "2.5"  "4"    "5.5"  NA    
as_canonical(v)
#> [1] -0.5  1.0  2.5  4.0  5.5   NA