View source: R/tensor-baseline-power.R
collapse2 | R Documentation |
Collapse high-dimensional tensor array
collapse2(x, keep, method = c("mean", "sum"), ...)
## S3 method for class 'FileArray'
collapse2(x, keep, method = c("mean", "sum"), ...)
## S3 method for class 'Tensor'
collapse2(x, keep, method = c("mean", "sum"), ...)
## S3 method for class 'array'
collapse2(x, keep, method = c("mean", "sum"), ...)
x |
R array, |
keep |
integer vector, the margins to keep |
method |
character, calculates mean or sum of the array when collapsing |
... |
passed to other methods |
A collapsed array (or a vector or matrix), depending on keep
collapse
x <- array(1:16, rep(2, 4))
collapse2(x, c(3, 2))
# Alternative method, but slower when `x` is a large array
apply(x, c(3, 2), mean)
# filearray
y <- filearray::as_filearray(x)
collapse2(y, c(3, 2))
collapse2(y, c(3, 2), "sum")
# clean up
y$delete(force = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.