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, usually a |

`margin` |
a vector giving the margins to compute sums for.
E.g., for a matrix |

### 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

### See Also

`rowSums`

and `colSums`

for similar functionality.

`proportions`

and `addmargins`

.

### Examples

```
m <- matrix(1:4, 2)
marginSums(m, 1) # = rowSums(m)
marginSums(m, 2) # = colSums(m)
DF <- as.data.frame(UCBAdmissions)
tbl <- xtabs(Freq ~ Gender + Admit, DF)
tbl
marginSums(tbl, "Gender") # a 1-dim "table"
rowSums(tbl) # a numeric vector
```

[Package

*base*version 4.4.1 Index]