

split {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)

