by                   package:base                   R Documentation

_A_p_p_l_y _a _F_u_n_c_t_i_o_n _t_o _a _D_a_t_a _F_r_a_m_e _s_p_l_i_t _b_y _F_a_c_t_o_r_s

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

     Function `by' is an object-oriented wrapper for `tapply' applied
     to data frames.

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

     by(data, INDICES, FUN, ...)

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

    data: an R object, normally a data frame, possibly a matrix.

 INDICES: a factor or a list of factors, each of length `nrow(x)'.

     FUN: a function to be applied to data frame subsets of `x'.

     ...: further arguments to `FUN'.

_D_e_t_a_i_l_s:

     A data frame is split by row into data frames subsetted by the
     values of one or more factors, and function `FUN' is applied to
     each subset in term.

     Object `data' will be coerced to a data frame by default.

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

     A list of class `"by"', giving the results for each subset.

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

     `tapply'

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

     data(warpbreaks)
     attach(warpbreaks)
     by(warpbreaks[, 1:2], tension, summary)
     by(warpbreaks[, 1], list(wool=wool, tension=tension), summary)
     by(warpbreaks, tension, function(x) lm(breaks ~ wool, data=x))
     detach("warpbreaks")

