aggregate: Aggregate

Description Usage Arguments Value Note See Also Examples

Description

Aggregate

Usage

1
2
3
4
5
6
7
aggregate(x, ...)

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

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

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.

...

Additional arguments.

Value

Modified object.

Note

Updated 2020-01-30.

See Also

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
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)
aggregate(counts, by = genes)

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

acidgenomics/basejump documentation built on Jan. 31, 2020, 6:45 p.m.