Title: | Construct Mixed Type Data Structures with Vectors of Vectors |
Version: | 0.1.0 |
Description: | Mixed type vectors are useful for combining semantically similar classes. Some examples of semantically related classes include time across different granularities (e.g. daily, monthly, annual) and probability distributions (e.g. Normal, Uniform, Poisson). These groups of vector types typically share common statistical operations which vary in results with the attributes of each vector. The 'vecvec' data structure facilitates efficient storage and computation across multiple vectors within the same object. |
License: | MIT + file LICENSE |
Imports: | rlang, vctrs |
Suggests: | lifecycle, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2.9000 |
NeedsCompilation: | no |
Packaged: | 2025-06-25 17:50:18 UTC; mitchell |
Author: | Mitchell O'Hara-Wild
|
Maintainer: | Mitchell O'Hara-Wild <mail@mitchelloharawild.com> |
Repository: | CRAN |
Date/Publication: | 2025-06-29 10:40:02 UTC |
vecvec: Construct Mixed Type Data Structures with Vectors of Vectors
Description
Mixed type vectors are useful for combining semantically similar classes. Some examples of semantically related classes include time across different granularities (e.g. daily, monthly, annual) and probability distributions (e.g. Normal, Uniform, Poisson). These groups of vector types typically share common statistical operations which vary in results with the attributes of each vector. The 'vecvec' data structure facilitates efficient storage and computation across multiple vectors within the same object.
Author(s)
Maintainer: Mitchell O'Hara-Wild mail@mitchelloharawild.com (ORCID)
Construct a vector of vectors
Description
new_vecvec() constructs a new vector of vectors from a list of vectors. It is meant to be performant, and does not check the inputs for correctness in any way. It is only safe to use after a call to df_list(), which collects and validates the columns used to construct the data frame.
Usage
new_vecvec(x = list(), loc = NULL, class = character())
Arguments
x |
An unnamed list of arbitrary vectors. |
loc |
A named list of value locations, with |
class |
Name of subclass. |
Value
A vector of vectors of class vecvec
.
Examples
# Create a vecvec prototype
new_vecvec()
# Construct a vecvec from a list of vectors
new_vecvec(list(letters, rnorm(10)))
# Fully specify a vecvec with locations
new_vecvec(
x = list(letters, rnorm(10)),
loc = list(
i = c(rep(1L, 3), rep(2L, 5), rep(1L, 23), rep(2L, 5)),
x = c(1:3, 1:5, 26:4, 6:10)
)
)
Convert a vecvec object into its underlying vector type
Description
Usage
unvecvec(x, ..., ptype = NULL)
Arguments
x |
A vecvec to unvecvec (convert to its underlying vector type) |
... |
These dots are for future extensions and must be empty. |
ptype |
If |
Value
A simple vector, all containing the same type of data.
Create a new vector of vectors
Description
Create a new vector of vectors
Usage
vecvec(...)
Arguments
... |
Vectors to combine into a single vector without type coercion. |
Value
A vector of vectors of class vecvec
.
See Also
unvecvec()
coerces the mixed-type vector into a single-typed
regular vector. new_vecvec()
is a performant alternative that accepts a
list of vectors rather than ...
(suitable for R packages).
Examples
vecvec(Sys.Date(), rnorm(3), letters)