ctab                 package:catspec                 R Documentation

_P_e_r_c_e_n_t_a_g_e _t_a_b_l_e_s

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

     Produces one-way, two-way or multi-way percentage tables

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

     ctab(..., dec.places=2, digits=dec.places, type=c("n", "row", "column", "total"),
     style="long", row.vars=NULL, col.vars=NULL, percentages=TRUE, addmargins=FALSE)

     ctab0(...)

     ## S3 method for class 'ctab':
     print(x, dec.places=x$dec.places, addmargins=x$addmargins, ...)

     ## S3 method for class 'ctab':
     summary(object,...)

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

     ...: either

             *  one or more factors,

             *  a class 'table' object,

             *  a class 'ftable' object,

             *  or a class 'ctab' object

dec.places: number of decimal places (default 2)

  digits: synonym for 'dec.places', for compatability with previous
          version

    type: Row, column, total percentages or counts ('type= n').
          Multiple values may be specified as a character vector.
          Partial matchin is used.

   style: Applicable if more than one percentage type is specified. If
          'style=long', percentages are printed underneath each other.
          If 'style=wide', the percentages are printed side by side

row.vars: Same as 'ftable': _"a vector of integers giving the numbers
          of the variables, or a character vector giving the names of
          the variables to be used for the rows of the [] table"_

col.vars: _"a vector of integers giving the numbers of the variables,
          or a character vector giving the names of the variables to be
          used for the columns of the [] table"_

percentages: If 'FALSE', proportions rather than percentages are
          printed

addmargins: Use 'addmargins=TRUE' to add subtotals to the table

       x: a 'ctab' object to be printed

  object: a 'ctab' object to be summarized

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

     'ctab' uses 'ftable' and 'prop.table' to produce one-way frequency
     tables, two-way crosstables, or multi-way percentage tables. More
     than one percentage type may be specified, in which case
     "percentage type" is an unnamed dimension of the table. 'row.vars'
     and 'col.vars' can be used to control the layout of multi-way
     tables using the facilities of 'ftable'. Subtotals can be added by
     specifiying 'addmargins=TRUE'. Note that '[gmodels]''CrossTable'
     in the 'gmodels' package also provides an easy method for
     producing percentage tables, but only for two-way tables.

     If 'ctab' is specified with no further options and for more than
     one factor, the output is identical to that of 'ftable'. If a
     single factor is specified, the default is to print the
     frequencies column-wise with the percentaqes next to them.

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

     An object of class "ctab". 'print.ctab' prints the table,
     'summary.ctab' passes the frequency table on to 'summary.table',
     which prints the number of cases, number of factors, and a
     chi-square test of independence. 

   table: A 'class(table)' object containing the table counts. Used by
          'summary.ctab' and by 'ctab' itself if a 'ctab' object is
          used as input.

    ctab: A 'class(ftable)' object containing the percentage types
          specified. This is printed by 'print.ctab'.

row.vars: The 'row.vars' options as numeric vectors

col.vars: The 'col.vars' options as numeric vectors

dec.places: The 'dec.places' option

    type: The 'type' option

   style: The 'style' option

percentages: The 'percentages' option

addmargins: The 'addmargins' option

_C_h_a_n_g_e_d _d_e_f_a_u_l_t_s _i_n _v_e_r_s_i_o_n _0._9_1:

     In version 0.90 of the 'catspec' package, the default was to treat
     the first factor as row variable, the second as column variable,
     the third and following as grouping variables. In version 0.91,
     the 'ftable' defaults are used instead. Use 'ctab0' to get the
     same variable order as before. 'ctab0' will print a line showing
     the 'row.vars' and 'col.vars' specifications to be used in future,
     as well as the regular output.

     The option name 'digits' has been replaced by 'dec.places', which
     I consider clearer. 'digits' remains a synonym for 'dec.places'.

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

     John Hendrickx <John_Hendrickx@yahoo.com>

_R_e_f_e_r_e_n_c_e_s:

     <URL: http://www.xs4all.nl/~jhckx/>

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

     'table', 'ftable', 'addmargins', 'prop.table', 'xtabs',
     '[gmodels]''CrossTable'

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

     ftable(Titanic)
     ctab(Titanic) # same output
     ctab(Titanic,type="r")
     ctab(Titanic,type=c("n","r"),addmargins=TRUE)
     ctab(Titanic,type=c("n","c","t","r"),style="w")
     mytab<-ftable(Titanic,row.vars=c(1,3),type="r")
     mytab
     ctab(mytab)
     newtab<-ctab(mytab,type="r")
     newtab
     summary(newtab)
     ctab0(Titanic,type="r")

     #second example using a data frame rather than table data
     data(logan)
     class(logan) #"data.frame"
     ctab(occ)
     ctab(occ,addmargins=TRUE)
     ctab(occ,style="w",type="c")
     ctab(occ,style="l",type="n")
     z<-ctab(occ,addmargins=TRUE,style="l")
     z
     print(z,addmargins=FALSE,dec.places=5)
     summary(z)

     t<-ctab(focc,occ,type=c("n","r","c"))
     t
     summary(t)

