marginSums {base} | R Documentation |
For a contingency table in array form, compute the sum of table entries for a given margin or set of margins.
marginSums(x, margin = NULL)
margin.table(x, margin = NULL)
x |
an array |
margin |
a vector giving the margins to compute sums for.
E.g., for a matrix |
The relevant marginal table, or just the sum of all entries if margin
has length zero. The class of x
is copied to the
output table if margin
is non-NULL.
margin.table
is an earlier name, retained for back-compatibility.
Peter Dalgaard
proportions
and addmargins
.
m <- matrix(1:4, 2)
marginSums(m, 1)
marginSums(m, 2)
DF <- as.data.frame(UCBAdmissions)
tbl <- xtabs(Freq ~ Gender + Admit, DF)
marginSums(tbl, "Gender")
proportions(tbl, "Gender")