| collapse | R Documentation |
Interface to the apply function for tagged arrays
collapse(object, drop.tags, keep.tags, FUN, tag.result=FALSE, ...)
object |
An array with a dimtags attribute |
drop.tags |
tags of dimensions to be dropped |
keep.tags |
tags of dimensions to be preserved |
FUN |
the function to be applied |
tag.result |
binary indicator. If TRUE then the result will also be a tagged array if possible |
... |
additional arguments passed to FUN |
Using the apply function to simplify high-dimensional arrays
can be complicated. This function provides a simplified interface for
tagged arrays with two advantages over the basic apply function:
Dimensions are referred to by name (dimtags), not by number.
The user can define ether the dimensions to be kept or the dimensions to be dropped (but not both).
Usually the output is a lower-dimensional array (vector, matrix, or
array). If the output cannot be simplified because FUN returns
values of varying length, the output will be a list.
If tag.result=TRUE, then the collapse function will add
dimtags to the result if it can. This is generally only possible if
FUN returns a scalar and the output is not a vector (which has
no dim attribute).
Tagging the result allows a further call to the collapse
function. For example, if MCMC output is represented as a tagged
array, we may wish to calculate the posterior mean within each chain,
and then the variance of the means between chains.
Martyn Plummer
dimtags, apply
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.