
extract, replace and combine greta arrays
Source:R/extract_replace_combine.R
extract-replace-combine.RdGeneric methods to extract and replace elements of greta arrays, or to combine greta arrays.
Usage
# S3 method for class 'greta_array'
x[...]
# S3 method for class 'greta_array'
x[...] <- value
# S3 method for class 'greta_array'
cbind(...)
# S3 method for class 'greta_array'
rbind(...)
# S3 method for class 'greta_array'
c(...)
# S3 method for class 'greta_array'
rep(x, ...)
# S3 method for class 'greta_array'
dim(x)
# S3 method for class 'greta_array'
length(x)
# S3 method for class 'greta_array'
dim(x) <- value
# S3 method for class 'greta_array'
head(x, n = 6L, ...)
# S3 method for class 'greta_array'
tail(x, n = 6L, ...)
# S3 method for class 'greta_array'
diag(x = 1, nrow, ncol)Arguments
- x
a greta array
- ...
either further indices specifying elements to extract or replace (
i,jfor[), or multiple greta arrays to combine (cbind(),rbind()&c()), or additional arguments (rep(),head(),tail()). Generic arguments such asdropandrecursiveare accepted but ignored for greta arrays.- value
for
[<-a greta array to replace elements, fordim<-either NULL or a numeric vector of dimensions- n
a single integer, as in
utils::head()andutils::tail()- nrow, ncol
optional dimensions for the resulting greta array when x is not a matrix.
Value
A greta_array, with elements extracted, replaced, or combined
as appropriate for the method called.
Details
diag() can be used to extract or replace the diagonal part of
a square and two-dimensional greta array, but it cannot be used to create a
matrix-like greta array from a scalar or vector-like greta array. A static
diagonal matrix can always be created with e.g. diag(3), and then
converted into a greta array.
Also note that since R 4.0.0, head and tail methods for arrays changed
to print a vector rather than maintain the array structure. The greta
package supports both methods, and will do so based on which version of R
you are using.
Syntax
These methods can be used with greta arrays as follows:
# extract
x[i]
x[i, j, ..., drop = FALSE]
head(x, n = 6L, ...)
tail(x, n = 6L, ...)
diag(x, nrow, ncol)
# replace
x[i] <- value
x[i, j, ...] <- value
diag(x) <- value
# combine
cbind(...)
rbind(...)
abind(...)
c(..., recursive = FALSE)
rep(x, times, ..., recursive = FALSE)
# get and set dimensions
length(x)
dim(x)
dim(x) <- value