marginSums {base} R Documentation

## Compute table margins

### Description

For a contingency table in array form, compute the sum of table entries for a given margin or set of margins.

### Usage

marginSums(x, margin = NULL)
margin.table(x, margin = NULL)


### Arguments

 x an array margin a vector giving the margins to compute sums for. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns. When x has named dimnames, it can be a character vector selecting dimension names.

### Value

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.

### Note

margin.table is an earlier name, retained for back-compatibility.

### Author(s)

Peter Dalgaard

proportions and addmargins.

### Examples

m <- matrix(1:4, 2)
marginSums(m, 1)
marginSums(m, 2)