percTable {NCStats}R Documentation

Express table entries as percentage of marginal table.

Description

Same as prop.table except that it returns percentages rather than proportions.

Usage

percTable(x, margin = NULL, digits = 1, addMargins = !is.na(ncol(x)))

Arguments

x

A frequency table likely constructed with table or xtabs.

margin

A numeric representing an index, or vector of indices, to generate the margin for – margin=1 computes row percentages, margin=2 computes column percentages, and margin=NULL (default) produces table percentages.

digits

A numeric indicating the number of decimals to round the percentages to.

addMargins

A logical indicating whether marginal totals should be appended to the table or not. If addMargins=TRUE then the appended marginal totals will correspond to which margin is chosen with margin= (as in addMargins).

Value

Same type as x except with percentages of a margin rather than frequencies.

Examples

d <- data.frame(Aye=sample(c("Yes","Si","Oui"),177,replace=TRUE),
                Bee=sample(c("Hum","Buzz"),177,replace=TRUE))

## 1-D
( A1 <- table(d$Aye) )
prop.table(A1)
percTable(A1)
percTable(A1,digits=3)
percTable(A1,addMargins=TRUE)
( A2 <- xtabs(~Aye,data=d) )
percTable(A2)

## 2-D
( AB1 <- table(d$Aye,d$Bee) )
percTable(AB1,margin=1)
percTable(AB1,margin=2)
percTable(AB1)
percTable(AB1,digits=3)
percTable(AB1,addMargins=FALSE)


[Package NCStats version 0.4.7 Index]