i

R Programming Complete Tutorial

R Contingency Tables

A contingency table is especially useful when a large number of observations need to be condensed into a smaller format, whereas a complex (flat) table is a type of contingency table used when constructing only one table, as opposed to several.

We can manipulate, alter, and produce table objects using the table() command to summarize a data sample, including vector, matrix, list, and data frame objects. We can also create a few particular kinds of table objects, like contingency tables and complex (flat) contingency tables using table() command.

Example:

We have two variables am (0 and 1) and cyl (4, 6, 8) in mtcars dataset. We can create a contingency table just using table () command mentioning the variables. This table will represent the relationship of each sample of the variable with all the samples of other variables. In this example, for 0 am, we have 3 4 cyl, 4 6cyl, and 12 8 cyl.