stack                 package:utils                 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, ...)
     ## Default S3 method:
     stack(x, ...)
     ## S3 method for class 'data.frame':
     stack(x, select, ...)

     unstack(x, ...)
     ## Default S3 method:
     unstack(x, form, ...)
     ## S3 method for class 'data.frame':
     unstack(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'.

     ...: further arguments passed to or from other methods.

_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', 'reshape'

_E_x_a_m_p_l_e_s:

     require(stats)
     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

