ftable.formula             package:base             R Documentation

_F_o_r_m_u_l_a _N_o_t_a_t_i_o_n _f_o_r _F_l_a_t _C_o_n_t_i_n_g_e_n_c_y _T_a_b_l_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Produce or manipulate a flat contingency table using formula
     notation.

_U_s_a_g_e:

     ftable(formula, data = NULL, subset, na.action, ...)

_A_r_g_u_m_e_n_t_s:

 formula: a formula object with both left and right hand sides
          specifying the column and row variables of the flat table.

    data: a data frame, list or environment containing the variables to
          be cross-tabulated, or a contingency table (see below).

  subset: an optional vector specifying a subset of observations to be
          used. Ignored if `data' is a contingency table.

na.action: a function which indicates what should happen when the data
          contain `NA's. Ignored if `data' is a contingency table.

     ...: further arguments to the default ftable method may also be
          passed as arguments, see `ftable.default'.

_D_e_t_a_i_l_s:

     This is a method of the generic function `ftable'.

     The left and right hand side of `formula' specify the column and
     row variables, respectively, of the flat contingency table to be
     created.  Only the `+' operator is allowed for combining the
     variables.  A `.' may be used once in the formula to indicate
     inclusion of all the ``remaining'' variables.

     If `data' is an object of class `"table"' or an array with more
     than 2 dimensions, it is taken as a contingency table, and hence
     all entries should be nonnegative.  Otherwise, if it is not a flat
     contingency table (i.e., an object of class `"ftable"'), it should
     be a data frame or matrix, list or environment containing the
     variables to be cross-tabulated.  In this case, `na.action' is
     applied to the data to handle missing values, and, after possibly
     selecting a subset of the data as specified by the `subset'
     argument, a contingency table is computed from the variables.

     The contingency table is then collapsed to a flat table, according
     to the row and column variables specified by `formula'.

_V_a_l_u_e:

     A flat contingency table which contains the counts of each
     combination of the levels of the variables, collapsed into a
     matrix for suitably displaying the counts.

_S_e_e _A_l_s_o:

     `ftable', `ftable.default'; `table'.

_E_x_a_m_p_l_e_s:

     data(Titanic)
     Titanic
     x <- ftable(Survived ~ ., data = Titanic)
     x
     ftable(Sex ~ Class + Age, data = x)

