Recall that a factor defines a partition into groups. Similarly a pair of factors defines a two way cross classification, and so on. The function table() allows frequency tables to be calculated from equal length factors. If there are k category arguments, the result is a k- way array of frequencies.
Suppose, for example, that statef is a factor giving the state code for each entry in a data vector. The assignment
statefr <- table(statef)
gives in statefr a table of frequencies of each state in the sample. The frequencies are ordered and labelled by the levels attribute of the category. This simple case is equivalent to, but more convenient than,
statefr <- tapply(statef, statef, length)
Further suppose that incomef is a category giving a suitably defined ``income class'' for each entry in the data vector, for example with the cut() function:
factor(cut(incomes,breaks=35+10*(0:7))) -> incomef
Then to calculate a two-way table of frequencies:
> table(incomef,statef)
act nsw nt qld sa tas vic wa
35+ thru 45 1 1 0 1 0 0 1 0
45+ thru 55 1 1 1 1 2 0 1 3
55+ thru 65 0 3 1 3 2 2 2 1
65+ thru 75 0 1 0 0 0 0 1 0
Extension to higher way frequency tables is immediate.