expand.grid               package:base               R Documentation

_C_r_e_a_t_e _a _D_a_t_a _F_r_a_m_e _f_r_o_m _A_l_l _C_o_m_b_i_n_a_t_i_o_n_s _o_f _F_a_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     Create a data frame from all combinations of the supplied vectors
     or factors.  See the description of the return value for precise
     details of the way this is done.

_U_s_a_g_e:

     expand.grid(..., KEEP.OUT.ATTRS = TRUE)

_A_r_g_u_m_e_n_t_s:

     ...: vectors, factors or a list containing these. 

KEEP.OUT.ATTRS: a logical indicating the '"out.attrs"' attribute (see
          below) should be computed and returned.

_V_a_l_u_e:

     A data frame containing one row for each combination of the
     supplied factors.  The first factors vary fastest.  The columns
     are labelled by the factors if these are supplied as named
     arguments or named components of a list.  The row names are
     'automatic'.

     Attribute '"out.attrs"' is a list which gives the dimension and
     dimnames for use by 'predict' methods.

_R_e_f_e_r_e_n_c_e_s:

     Chambers, J. M. and Hastie, T. J. (1992) _Statistical Models in
     S._ Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'combn' (package 'utils') for the generation of all combinations
     of n elements, taken m at a time.

_E_x_a_m_p_l_e_s:

     require(utils)

     expand.grid(height = seq(60, 80, 5), weight = seq(100, 300, 50),
                 sex = c("Male","Female"))

     x <- seq(0,10, length.out=100)
     y <- seq(-1,1, length.out=20)
     d1 <- expand.grid(x=x, y=y)
     d2 <- expand.grid(x=x, y=y, KEEP.OUT.ATTRS = FALSE)
     object.size(d1) - object.size(d2)
     ##-> 5992 or 8832 (on 32- / 64-bit platform)

