The `table()`

function in R is used to create… a table. So far, so good. In fact, this is a rather simple function that gathers data and creates a contingency table or frequency table, in other words, a table which counts the **number of occurrences** of any unique value in a data set. Let’s check the following example where we store a random a random list of numbers in the range 1:5.

[code language=”r”]

random.list <- c(1,5,3,4,2,5,4,3,1,2,4,5,1,3,2,4,5,1,2,3,1,4,5,2,3,1,5,5,2,1)

random.list

table(random.list)

[/code]

The function `table()`

counts how many “1”, “2”, “3”, “4” and “5” are in the object `random.list`

and provides a very simple frequency table where we can read for instance that the number 3 is found five times and the number 5 is found seven times.