tapplySimpl             package:sfsmisc             R Documentation

_M_o_r_e _s_i_m_p_l_i_f_i_c_a_t_i_o_n _i_n _t_a_p_p_l_y() _r_e_s_u_l_t

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

     tapplySimpl(X, INDEX, FUN, ...)

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

       X: an atomic object, typically a vector.  All these arguments
          are as in 'tapply()' and are passed to 'tapply(..)'.

   INDEX: list of (typically more than one) factors, each of same
          length as 'X'.

     FUN: the function to be applied.  For the result to be
          simplifiable, 'FUN()' must return a vector of always the same
          length.

     ...: optional arguments to 'FUN'.

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

     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()'.

_A_u_t_h_o_r(_s):

     Martin Maechler, 14 Jun 1993 (for S-plus).

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

     'tapply(*, simplify=TRUE)'.

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

       ## 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)

