Learn R Programming

descriptr (version 0.1.0)

cross_table: Two Way Tables

Description

cross_table creates two way tables of categorical variables. The tables created can be visualized as barplots and mosaicplots.

Usage

cross_table(var1, var2)

# S3 method for cross_table plot(x, beside = FALSE, proportional = FALSE, ...)

# S3 method for cross_table mosaicplot(x, ...)

Arguments

var1

First categorical variable

var2

Second categorical variable

x

An object of class cross_table

beside

a logical value. If FALSE, the columns of height are portrayed as stacked bars, and if TRUE the columns are portrayed as juxtaposed bars.

proportional

a logical value. If TRUE, the height of the bars is proportional

...

further arguments to be passed to or from methods.

Value

cross_table returns an object of class "cross_table". An object of class "cross_table" is a list containing at least the following components:

obs

obs number of observations

var2_levels

levels of the second categorical variable

var1_levels

levels of the first categorical variable

varnames

names of the variables

twowaytable

table of the variables

percent_table

table of percentages

row_percent

table of row percentages

col_percent

table of column percentages

column_totals

total of columns

percent_column

total of columns as a percentage

Examples

Run this code
k <- cross_table(mtcars$cyl, mtcars$am)

# bar plots
plot(k)
plot(k, beside = TRUE)
plot(k, proportional = TRUE)

# mosaic plots
mosaicplot(k)

Run the code above in your browser using DataLab