

_A_p_p_l_y _a _F_u_n_c_t_i_o_n _O_v_e_r _a ``_R_a_g_g_e_d'' _A_r_r_a_y

     tapply(X, INDEX, FUN = NULL, simplify = TRUE, ...)

_A_r_g_u_m_e_n_t_s:

       X: an atomic object, typically a vector.

   INDEX: list of factors, each of same length as `X'.

     FUN: the function to be applied.  In the case of func-
          tions like `+', `%*%', etc., the function name
          must be quoted.  If `FUN' is `NULL', tapply
          returns a vector which can be used to subscript
          the multi-way array `tapply' normally produces.

simplify: If `FALSE', `tapply' always returns an array of
          mode `"list"'.  If `TRUE' (the default), then if
          `FUN' always returns a scalar, `tapply' returns an
          array with the mode of the scalar, and if the
          array would be one dimensional the dimension is
          removed, to make it a vector.

     ...: optional arguments to `FUN'.

_V_a_l_u_e:

     When `FUN' is present, `tapply' calls `FUN' for each
     cell that has any data in it.  If `FUN' returns a sin-
     gle atomic value for each cell (e.g., functions `mean'
     or `var'), then `tapply' returns a multi-way array con-
     taining the values.  The array has the same number of
     dimensions as `INDEX' has components; the number of
     levels in a dimension is the number of levels (`nlev-
     els(.)') in the corresponding component of `INDEX'.
     This is a vector if `INDEX' has only one component.

     If `FUN' does not return a single atomic value, `tap-
     ply' returns an array of mode `"list"' whose components
     are the values of the individual calls to `FUN', i.e.,
     the result is a list with a `dim' attribute.

_S_e_e _A_l_s_o:

     `apply', `lapply' with its version `sapply'.

_E_x_a_m_p_l_e_s:

     groups <- as.factor(rbinom(32, n = 5, p = .4))
     tapply(groups, groups, length) #- is almost the same as
     table(groups)

     n <- 17; fac <- factor(rep(1:3, len = n), levels = 1:5)
     table(fac)
     tapply(1:n, fac, sum)
     tapply(1:n, fac, sum, simplify = FALSE) #- does not yet print okay
     tapply(1:n, fac, range)                 #- .. nor does this
     tapply(1:n, fac, quantile)              #- ... or this

     ind <- list(c(1, 2, 2), c("A", "A", "B"))
     table(ind)
     tapply(1:3, ind) #-> the split vector
     tapply(1:3, ind, sum)

