## S3 method for class 'default':
PercTable(x, y = NULL, \dots)
## S3 method for class 'table':
PercTable(tab, row.vars = NULL, col.vars = 2, digits = 3, big.mark = "", pfmt = FALSE,
freq = TRUE, rfrq = "100", expected = FALSE, residuals = FALSE,
stdres = FALSE, margins = NULL, \dots)
## S3 method for class 'formula':
PercTable(formula, data, subset, na.action, \dots)
MarginTable(tab)
table(x, y)
.
If x is a matrix, it will be coerced to a table via as.table(x).lhs ~ rhs
where lhs
will be tabled versus rhs (table(lhs, rhs)
).model.frame
) containing the variables in the formula formula
.
By default the variables are taken from environment(formula)
getOption("na.action")
.PercTable.default()
to the PercTable.table()
."ftable"
.ftable
.
By means of row.vars
, resp. col.vars
, the structure of the table can be defined. row.vars
can either be the names of
the dimensions (included percentages are named "idx"
) or numbers (1:3, where 1 is the first dimension of the table,
2 the second and 3 the percentages).
Use Sort()
if you want to have your table sorted by rows.
MarginTable returns a list containing all the margin tables of a n-dimensional table along all dimensions. It does not much more than margin.table
besides add percentages and do the job for all the dimensions.Freq
, table
, ftable
, prop.table
, addmargins
There are similar functions in package printTable2
and package table2d_summary
, both
lacking some of the flexibility we needed here.tab <- table(d.pizza$driver, d.pizza$area)
PercTable(tab=tab, col.vars=2)
PercTable(tab=tab, col.vars=2, margins=c(1,2))
PercTable(tab=tab, col.vars=2, margins=2)
PercTable(tab=tab, col.vars=2, margins=1)
PercTable(tab=tab, col.vars=2, margins=NULL)
PercTable(tab=tab, col.vars=2, rfrq="000")
# just the percentages without absolute values
PercTable(tab=tab, col.vars=2, rfrq="110", freq=FALSE)
# just the row percentages in percent format (pfmt = TRUE)
PercTable(tab, freq= FALSE, rfrq="010", pfmt=TRUE, digits=1)
# just the expected frequencies and the standard residuals
PercTable(tab=tab, rfrq="000", expected = TRUE, stdres = TRUE)
# rearrange output such that freq are inserted as columns instead of rows
PercTable(tab=tab, col.vars=c(3,2), rfrq="111")
# putting the cities in rows
PercTable(tab=tab, col.vars=c(3,1), rfrq="100", margins=c(1,2))
# formula interface with subset
PercTable(driver ~ area, data=d.pizza, subset=wine_delivered==0)
# sort the table by rows, order first column (Zurich), then third, then row.names (0)
PercTable(tab=Sort(tab, ord=c(1,3,0)))
# the vector interface
PercTable(x=d.pizza$driver, y=d.pizza$area)
PercTable(x=d.pizza$driver, y=d.pizza$area, margins=c(1,2), rfrq="000", useNA="ifany")
# one dimensional x falls back to the function Freq()
PercTable(x=d.pizza$driver)
# the margin tables
MarginTable(Titanic)
Run the code above in your browser using DataLab