Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pctab

Create percentages in a table


Description

Computes percentages and a margin of totals along a given margin of a table.

Usage

pctab(TT, margin = length(dim(TT)), dec=1)

Arguments

TT

A table or array object

margin

Which margin should be the the total?

dec

How many decimals should be printed? If 0 or FALSE nothing is printed

Value

A table of percentages, where all dimensions except the one specified margin has two extra levels named "All" (where all entries are 100) and "N". The function prints the table with dec decimals.

Author(s)

Bendix Carstensen, Steno Diabetes Center, http://bendixcarstensen.com.

See Also

Examples

Aye <- sample( c("Yes","Si","Oui"), 177, replace=TRUE )
Bee <- sample( c("Hum","Buzz"), 177, replace=TRUE )
Sea <- sample( c("White","Black","Red","Dead"), 177, replace=TRUE )
A <- table( Aye, Bee, Sea )
A
ftable( pctab( A ) )
ftable( pctab( addmargins( A, 1 ), 3 ) )
round( ftable( pctab( addmargins( A, 1 ), 3 ), row.vars=3 ), 1)

Epi

Statistical Analysis in Epidemiology

v2.44
GPL-2
Authors
Bendix Carstensen [aut, cre], Martyn Plummer [aut], Esa Laara [ctb], Michael Hills [ctb]
Initial release
2021-02-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.