Description Usage Arguments Details Value Author(s) Examples
View source: R/summarizeRows.R
Apply a function to summarize rows/columns that assigned to the same level by a factor vector.
1 | summarizeRows(matrix, factor, fun = mean, ...)
|
matrix |
A numeric matrix |
factor |
A vector of factors, either of the length of
|
fun |
A function or a name for a function, the summarizing function applied to rows/columns sharing the same level |
... |
Further parameters passed to the function |
NA
levels are neglected, and corresponding rows/columns will not
contribute to the summarized matrix.
summarizeCols
is synonymous to summarizeColumns
A matrix, the dimension will be determined by the number of levels of the factor vector.
Jitao David Zhang <jitao_david.zhang@roche.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | my.matrix <- matrix(1:25, nrow=5)
print(my.matrix)
my.factor <- factor(c("A", "B", "A", "C", "B"))
summarizeRows(matrix=my.matrix, factor=my.factor, fun=mean)
summarizeRows(matrix=my.matrix, factor=my.factor, fun=prod)
summarizeColumns(matrix=my.matrix, factor=my.factor, fun=mean)
summarizeColumns(matrix=my.matrix, factor=my.factor, fun=prod)
## NA values in factor
my.na.factor <- factor(c("A", "B", "A", "C", NA))
summarizeRows(matrix=my.matrix, factor=my.na.factor, fun=mean)
summarizeRows(matrix=my.matrix, factor=my.na.factor, fun=prod)
summarizeColumns(matrix=my.matrix, factor=my.na.factor, fun=mean)
summarizeColumns(matrix=my.matrix, factor=my.na.factor, fun=prod)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.