prettytable: Printing 1 & 2 Way Frequency Tables With Relative Proportions

View source: R/prettytable.R

prettytableR Documentation

Printing 1 & 2 Way Frequency Tables With Relative Proportions

Description

Automatically append relative proportions/percentages to raw counts calculated from table(). Currently only works for 1 and 2 way frequency tables.

Usage

prettytable(mytable, margin = 1)

Arguments

margin

Defaults to 1, calculate row-wise proportions. Change to 2 to calculate column-wise proportions.

table

A table object from table().

Value

Returns a table with relative proportions/percentages appended to raw counts.

Examples

mydata <- data.frame(x1 = rep(c("Male","Female","Male"), 100), x2 = rep(c("High","Medium","Low"),100))
# two way frequency table
a <- table(mydata$x1,mydata$x2)
prettytable(a)
# feed it into kable for a prettier table
knitr::kable(prettytable(a), align = "c")
# one way frequency table
a <- table(mydata$x1)
prettytable(a)

Aaron0696/aaRon documentation built on July 27, 2023, 2:05 p.m.