stack-methods {S4Vectors} | R Documentation

## Stack objects

### Description

The S4Vectors package defines `stack` methods for List and `matrix` objects.

It also introduces `mstack()`, a variant of `stack` where the list is taken as the list of arguments in `...`.

### Usage

    ## S4 method for signature 'List'
    stack(x, index.var="name", value.var="value", name.var=NULL)

    ## S4 method for signature 'matrix'
    stack(x, row.var=names(dimnames(x))[1L],
          col.var=names(dimnames(x))[2L],
          value.var="value")

    mstack(..., .index.var="name")

### Arguments

`x` | A List derivative (for the `stack` method for List objects), or a `matrix` (for the `stack` method for `matrix` objects).
`index.var, .index.var` | A single string specifying the column name for the index (source name) column.
`value.var` | A single string specifying the column name for the values.
`name.var` | TODO
`row.var, col.var` | TODO
`...` | The objects to stack. Each of them should be a Vector or `vector` (mixing the two will not work).

### Details

As with `stack` on a `list`, `stack` on a List derivative constructs a DataFrame with two columns: one for the unlisted values, the other indicating the name of the element from which each value was obtained. `index.var` specifies the column name for the index (source name) column and `value.var` specifies the column name for the values.

[TODO: Document `stack()` method for `matrix` objects.]

### See Also

- `stack` in the utils package.

- List and DataFrame objects.

### Examples

    library(IRanges)
    starts <- IntegerList(c(1, 5), c(2, 8))
    ends <- IntegerList(c(3, 8), c(5, 9))
    rgl <- IRangesList(start=starts, end=ends)
    rangeDataFrame <- stack(rgl, "space", "ranges")

[Package S4Vectors version 0.28.1 Index]