stack                  package:base                  R Documentation

_S_t_a_c_k _o_r _U_n_s_t_a_c_k _V_e_c_t_o_r_s _f_r_o_m _a _D_a_t_a _F_r_a_m_e _o_r _L_i_s_t

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

     Stacking vectors concatenates multiple vectors into a single
     vector along with a factor indicating where each observation
     originated. Unstacking reverses this operation.

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

     stack(x, ...)
     stack.default(x)
     stack.data.frame(x, select)
     unstack(x, ...)
     unstack.default(x, form)
     unstack.data.frame(x, form)

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

       x: object to be stacked or unstacked

  select: expression, indicating variables to select from a data frame

    form: a two-sided formula whose left side evaluates to the vector
          to be unstacked and whose right side evaluates to the
          indicator of the groups to create.  Defaults to `formula(x)'
          in `unstack.data.frame'.

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

     The `stack' function is used to transform data available as
     separate columns in a data frame or list into a single column that
     can be used in an analysis of variance model or other linear
     model.  The `unstack' function reverses this operation.

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

     `unstack' produces a list of columns according to the formula
     `form'.  If all the columns have the same length, the resulting
     list is coerced to a data frame.

     `stack' produces a data frame with two columns 

  values: the result of concatenating the selected vectors in `x'

     ind: a factor indicating from which vector in `x' the observation
          originated

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

     Douglas Bates

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

     `lm'

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

     data(PlantGrowth)
     formula(PlantGrowth)         # check the default formula
     pg <- unstack(PlantGrowth)   # unstack according to this formula
     pg
     stack(pg)                    # now put it back together
     stack(pg, select = -ctrl)    # omitting one vector

