Description Usage Arguments Details Value Author(s) References See Also Examples
Produces oneway, twoway or multiway percentage tables
1 2 3 4 5 6 7 
... 
either

dec.places 
number of decimal places (default 2) 
digits 
synonym for 
type 
Row, column, total percentages or counts ( 
style 
Applicable if more than one percentage type is specified. If 
row.vars 
Same as 
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 
addmargins 
Use 
x 
is a tables object created by 
object 
is a tables object created by 
Options have default NULL so attributes of a ctab object can be used as default. In other cases, the following options will be used if nothing has been specified:
1 2 
ctab
uses ftable
and prop.table
to produce oneway frequency tables, twoway crosstables, or multiway 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 multiway tables using the facilities of ftable
. Subtotals can be added by specifiying addmargins=TRUE
.
CrossTable
in the gmodels
package also provides an easy method for producing percentage tables, but is restricted to twoway 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 columnwise with the percentaqes next to them.
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 chisquare test of independence.
table 
A 
ctab 
A 
row.vars 
The 
col.vars 
The 
dec.places 
The 
type 
The 
style 
The 
percentages 
The 
addmargins 
The 
John Hendrickx <[email protected]>
http://home.wanadoo.nl/john.hendrickx/statres/
table
, ftable
, addmargins
, prop.table
, xtabs
, [gmodels]
CrossTable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  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)
#second example using a data frame rather than table data
library(survival)
data(logan)
attach(logan)
class(logan) #"data.frame"
ctab(occupation)
ctab(occupation,addmargins=TRUE)
ctab(occupation,style="w",type="c")
ctab(occupation,style="l",type="n")
z<ctab(occupation,addmargins=TRUE,style="l")
z
print(z,addmargins=FALSE,dec.places=5)
summary(z)
t<ctab(focc,occupation,type=c("n","r","c"))
t
summary(t)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.