Debian Codegraph @

man/tapplySimpl.Rd

raw
1 \name{tapplySimpl}
2 \alias{tapplySimpl}
3 \title{More simplification in tapply() result}
4 \description{
5 For the case of more than two categories or indices (in \code{INDEX}),
6 traditional \code{\link{tapply}(*, simplify = TRUE)} still returns a
7 list when an array may seem more useful and natural. This is provided
8 by \code{tapplySimpl()} if the function \code{FUN()} is defined such
9 as to return a vector of the same length in all cases.
10 }
11 \usage{
12 tapplySimpl(X, INDEX, FUN, \dots)
13 }
14 \arguments{
15 \item{X}{an atomic object, typically a vector. All these arguments
16 are as in \code{\link{tapply}()} and are passed to \code{tapply(..)}.}
17 \item{INDEX}{list of (typically more than one) factors, each of same
18 length as \code{X}.}
19 \item{FUN}{the function to be applied. For the result to be
20 simplifiable, \code{FUN()} must return a vector of always the same
21 length.}
22 \item{\dots}{optional arguments to \code{FUN}.}
23 }
24 \value{
25 If the above conditions are satisfied, the list returned from
26 \code{r <- tapply(X, INDEX, FUN, \dots)} is simplified into an
27 \code{\link{array}} of rank \eqn{1 + \#\{indices\}}, i.e.,
28 \code{1+length(INDEX)}; otherwise, \code{tapplySimpl()} returns the list
29 \code{r}, i.e., the same as \code{tapply()}.
30 }
31 \author{Martin Maechler, 14 Jun 1993 (for S-plus).}
32 \seealso{\code{\link{tapply}(*, simplify=TRUE)}.}
33 \examples{
34 ## Using tapply() would give a list (with dim() of a matrix);
35 ## here we get 3-array:
36
37 data(esoph)
38 with(esoph, {
39 mima <<- tapplySimpl(ncases/ncontrols, list(agegp, alcgp), range)
40 stopifnot(dim(mima) == c(2, nlevels(agegp), nlevels(alcgp)))
41 })
42 aperm(mima)
43 }
44 \keyword{iteration}
45 \keyword{category}