split                  package:base                  R Documentation

_D_i_v_i_d_e _i_n_t_o _G_r_o_u_p_s

_D_e_s_c_r_i_p_t_i_o_n:

     `split' divides the data in the vector `x' into the groups defined
     by the factor `f'.

_U_s_a_g_e:

     split(x, f)
     split.default(x, f)
     split.data.frame(x, f)

_A_r_g_u_m_e_n_t_s:

       x: vector containing the values to be divided into groups.

       f: a ``factor'' such that `as.factor(f)' defines the grouping.

_D_e_t_a_i_l_s:

     `f' is recycled as necessary and if the length of `x' is not a
     multiple of the length of `f' a warning is printed.

_V_a_l_u_e:

     The value returned is a list of vectors containing the values for
     the groups.  The components of the list are named by the factor
     levels of `f'. If `f' is longer than `x' some of these will be of
     zero length.

_S_e_e _A_l_s_o:

     `cut'

_E_x_a_m_p_l_e_s:

     n <- 10; nn <- 100
     g <- factor(round(n * runif(n * nn)))
     x <- rnorm(n * nn) + sqrt(codes(g))
     xg <- split(x, g)
     boxplot(xg, col = "lavender", notch = TRUE, varwidth = TRUE)
     sapply(xg, length)
     sapply(xg, mean)

     ## Split a matrix into a list by columns
     ma <- cbind(x = 1:10, y = (-4:5)^2)
     split(ma, col(ma))

     split(1:10, 1:2)

