tapplySimpl | R Documentation |
For the case of more than two categories or indices (in INDEX
),
traditional tapply(*, simplify = TRUE)
still returns a
list when an array may seem more useful and natural. This is provided
by tapplySimpl()
if the function FUN()
is defined such
as to return a vector of the same length in all cases.
tapplySimpl(X, INDEX, FUN, ...)
X |
an atomic object, typically a vector. All these arguments
are as in |
INDEX |
list of (typically more than one) factors, each of same
length as |
FUN |
the function to be applied. For the result to be
simplifiable, |
... |
optional arguments to |
If the above conditions are satisfied, the list returned from
r <- tapply(X, INDEX, FUN, ...)
is simplified into an
array
of rank 1 + \#\{indices\}
, i.e.,
1+length(INDEX)
; otherwise, tapplySimpl()
returns the list
r
, i.e., the same as tapply()
.
Martin Maechler, 14 Jun 1993 (for S-plus).
tapply(*, simplify=TRUE)
.
## Using tapply() would give a list (with dim() of a matrix);
## here we get 3-array:
data(esoph)
with(esoph, {
mima <<- tapplySimpl(ncases/ncontrols, list(agegp, alcgp), range)
stopifnot(dim(mima) == c(2, nlevels(agegp), nlevels(alcgp)))
})
aperm(mima)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.