Title: | Environments Behaving (Almost) as Lists |
---|---|
Description: | List environments are environments that have list-like properties. For instance, the elements of a list environment are ordered and can be accessed and iterated over using index subsetting, e.g. 'x <- listenv(a = 1, b = 2); for (i in seq_along(x)) x[[i]] <- x[[i]] ^ 2; y <- as.list(x)'. |
Authors: | Henrik Bengtsson [aut, cre, cph] |
Maintainer: | Henrik Bengtsson <[email protected]> |
License: | LGPL (>= 2.1) |
Version: | 0.9.1 |
Built: | 2024-12-19 06:52:38 UTC |
Source: | CRAN |
Transpose a 'listenv' array by permuting its dimensions
## S3 method for class 'listenv' aperm(a, perm, ...) ## S3 method for class 'listenv' t(x)
## S3 method for class 'listenv' aperm(a, perm, ...) ## S3 method for class 'listenv' t(x)
a , x
|
(listenv) The list environment to be transposed |
perm |
(integer vector) An index vector of length |
... |
Additional arguments passed to |
Returns a list environment with permuted dimensions
These functions works like base::aperm()
and base::t()
.
x <- as.listenv(1:6) dim(x) <- c(2, 3) dimnames(x) <- list(letters[1:2], LETTERS[1:3]) print(x) x <- t(x) print(x) x <- aperm(x, perm = 2:1) print(x)
x <- as.listenv(1:6) dim(x) <- c(2, 3) dimnames(x) <- list(letters[1:2], LETTERS[1:3]) print(x) x <- t(x) print(x) x <- aperm(x, perm = 2:1) print(x)
Set the dimension of an object
dim_na(x) <- value
dim_na(x) <- value
x |
An R object, e.g. a list environment, a matrix, an array, or a data frame. |
value |
A numeric vector coerced to integers.
If one of the elements is missing, then its value is inferred from the
other elements (which must be non-missing) and the length of |
An object with the dimensions set, similar to what
dim(x) <- value
returns.
x <- 1:6 dim_na(x) <- c(2, NA) print(dim(x)) ## [1] 2 3
x <- 1:6 dim_na(x) <- c(2, NA) print(dim(x)) ## [1] 2 3
Create a list environment
listenv(...) as.listenv(...)
listenv(...) as.listenv(...)
... |
(optional) Named and/or unnamed objects to be assigned to the list environment. |
An environment of class listenv
.
x <- listenv(c = 2, a = 3, d = "hello") print(names(x)) names(x)[2] <- "A" x$b <- 5:8 y <- as.list(x) str(y) z <- as.listenv(y)
x <- listenv(c = 2, a = 3, d = "hello") print(names(x)) names(x)[2] <- "A" x$b <- 5:8 y <- as.list(x) str(y) z <- as.listenv(y)