powered by
For a contingency table in array form, compute the sum of table entries for a given index.
margin.table(x, margin = NULL)
an array
index number (1 for rows, etc.)
The relevant marginal table. The class of x is copied to the output table, except in the summation case.
x
This is really just apply(x, margin, sum) packaged up for newbies, except that if margin has length zero you get sum(x).
apply(x, margin, sum)
margin
sum(x)
prop.table and addmargins.
prop.table
addmargins
m <- matrix(1:4, 2) margin.table(m, 1) margin.table(m, 2)
Run the code above in your browser using DataLab