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

colPercents

Row, Column, and Total Percentage Tables


Description

Percentage a matrix or higher-dimensional array of frequency counts by rows, columns, or total frequency.

Usage

colPercents(tab, digits=1)
rowPercents(tab, digits=1)
totPercents(tab, digits=1)

Arguments

tab

a matrix or higher-dimensional array of frequency counts.

digits

number of places to the right of the decimal place for percentages.

Value

Returns an array of the same size and shape as tab percentaged by rows or columns, plus rows or columns of totals and counts, or by the table total.

Author(s)

Examples

if (require(car)){
    data(Mroz) # from car package
    cat("\n\n column percents:\n")
    print(colPercents(xtabs(~ lfp + wc, data=Mroz)))
    cat("\n\n row percents:\n")
    print(rowPercents(xtabs(~ hc + lfp, data=Mroz)))
    cat("\n\n total percents:\n")
    print(totPercents(xtabs(~ hc + wc, data=Mroz)))
    cat("\n\n three-way table, column percents:\n")
    print(colPercents(xtabs(~ lfp + wc + hc, data=Mroz)))
}

RcmdrMisc

R Commander Miscellaneous Functions

v2.7-1
GPL (>= 2)
Authors
John Fox [aut, cre], Robert Muenchen [ctb], Dan Putler [ctb]
Initial release
2020-08-12

We don't support your browser anymore

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