aggregateRows: Aggregate rows

Description Usage Arguments Value Methods (by class) Author(s) Examples

Description

Aggregate rows

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
aggregateRows(x, ...)

## S4 method for signature 'matrix'
aggregateRows(x, by, fun = c("sum", "mean", "median", "geometricMean", "n"))

## S4 method for signature 'Matrix'
aggregateRows(x, by, fun = c("sum", "mean"))

## S4 method for signature 'SummarizedExperiment'
aggregateRows(x, col = "aggregate", fun = "sum")

Arguments

x

Object.

by

factor. Aggregation groupings. The new aggregate names are defined as the factor levels, and the original, unaggregated names are defined as the names.

fun

character(1). Name of the aggregation function to apply. Uses match.arg() internally.

col

character(1). Name of column in either rowData() or colData() that defines the desired aggregation groupings.

...

Additional arguments.

Value

Modified object of same class, with rows aggregated.

Methods (by class)

Author(s)

Michael Steinbaugh, Rory Kirchner

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
counts <- matrix(
    data = c(
        0L, 2L, 2L, 2L,
        2L, 0L, 2L, 2L,
        2L, 2L, 0L, 2L,
        2L, 2L, 2L, 0L
    ),
    nrow = 4L,
    ncol = 4L,
    byrow = TRUE,
    dimnames = list(
        paste0("transcript", seq_len(4L)),
        paste(
            paste0("sample", rep(seq_len(2L), each = 2L)),
            paste0("replicate", rep(seq_len(2L), times = 2L)),
            sep = "_"
        )
    )
)

genes <- factor(paste0("gene", rep(seq_len(2L), each = 2L)))
names(genes) <- rownames(counts)
print(genes)

## matrix ====
print(counts)
aggregateRows(counts, by = genes)

## Matrix ====
sparse <- as(counts, "sparseMatrix")
print(sparse)
aggregateRows(sparse, by = genes)

## SummarizedExperiment ====
se <- SummarizedExperiment::SummarizedExperiment(
    assays = SimpleList(counts = counts),
    rowData = DataFrame(aggregate = genes)
)
print(se)
aggregateRows(se)

acidgenomics/basejump documentation built on March 22, 2020, 4:24 a.m.