.BG
.FN tapply
.TL
Apply a Function to a Ragged Array
.CS
tapply(X, INDICES, FUN, ...)
.AG X
vector of data to be grouped by `indices'.
Missing values (`NA's) are allowed if `FUN' accepts them.
.AG INDICES
list whose elements are interpreted as categories, each of
the same length as `x'.
The elements of the categories define the position in a multi-way
array corresponding to each `x' observation.
Missing values (`NA's) are allowed.
.AG FUN
function or character string giving the name of the function to be
applied to each cell.
If `FUN' is omitted, `tapply' returns a vector that can be
used to subscript the multi-way array that `tapply' normally produces.
This vector is useful for computing residuals.
See the example.
.AG ...
optional arguments to be given to each invocation of `FUN'.
.RT
`tapply' calls `FUN' for each cell that has any data in it.
If `FUN' returns a single atomic value for each cell (e.g. functions `mean' or
`var'), then `tapply' returns a multi-way array
containing the values.  Otherwise, `tapply' returns an array of mode `"list"',
whose elements are the values of the individual calls to `FUN'.
.EX
# generate mean republican votes for regions of the U.S.
# category that gives the region for each observation
region <- state.region[row(votes.repub)]
election <- category(votes.year)[col(votes.repub)]
mn <- tapply(votes.repub,list(region,election),mean)
round(mn,1)  # table of mean vote by region and election
positions <- tapply(votes.repub,list(region,election))
residuals <- votes.repub - mn[positions]
.KW iteration
.KW category
.KW array
.WR
