render_template(name, data, path = "")
""
(the
default), prints to standard out.Render template.
rd <- parse_rd("colSums", "base") html <- to_html(rd, package = "base") render_template("topic", html)Form Row and Column Sums and Means. Form Row and Column Sums and Means
Usage
colSums(x, na.rm = FALSE, dims = 1) rowSums(x, na.rm = FALSE, dims = 1) colMeans(x, na.rm = FALSE, dims = 1) rowMeans(x, na.rm = FALSE, dims = 1) .colSums(X, m, n, na.rm = FALSE) .rowSums(X, m, n, na.rm = FALSE) .colMeans(X, m, n, na.rm = FALSE) .rowMeans(X, m, n, na.rm = FALSE)Arguments
- x
- an array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame.
- na.rm
- logical. Should missing values (including
NaN
) be omitted from the calculations?- dims
- integer: Which dimensions are regarded as rows or columns to sum over. For
row*
, the sum or mean is over dimensionsdims+1, ...
; forcol*
it is over dimensions1:dims
.- X
- a numeric matrix.
- m, n
- the dimensions of X.
Description
Form row and column sums and means for numeric arrays.
Details
These functions are equivalent to use of
apply
withFUN = mean
orFUN = sum
with appropriate margins, but are a lot faster. As they are written for speed, they blur over some of the subtleties ofNaN
andNA
. Ifna.rm = FALSE
and eitherNaN
orNA
appears in a sum, the result will be one ofNaN
orNA
, but which might be platform-dependent.Notice that omission of missing values is done on a per-column or per-row basis, so column means may not be over the same set of rows, and vice versa. To use only complete rows or columns, first select them with
na.omit
orcomplete.cases
(possibly on the transpose ofx
). The versions with an initial dot in the name are bare-bones versions for use in programming: they apply only to numeric matrices and do not name the result.Value
A numeric or complex array of suitable size, or a vector if the result is one-dimensional. For the first four functions the
dimnames
(ornames
for a vector result) are taken from the original array.If there are no values in a range to be summed over (after removing missing values with
na.rm = TRUE
), that component of the output is set to0
(*Sums
) orNaN
(*Means
), consistent withsum
andmean
.Examples
## Compute row and column sums for a matrix: x <- cbind(x1 = 3, x2 = c(4:1, 2:5)) rowSums(x); colSums(x)x1 x2 24 24x1 x2 3 3x1 x2 24 24x1 x2 0 3x <- cbind(x1 = 3, x2 = c(4:1, 2:5)) x[3, ] <- NA; x[4, 2] <- NA rowSums(x); colSums(x); rowMeans(x); colMeans(x)x1 x2 NA NAx1 x2 21 21x1 x2 3.0 3.5[1] 2 2 6Gender Admit Male Female Admitted 1198 557 Rejected 1493 1278A B C D E F 933 585 918 792 584 714## complex case x <- cbind(x1 = 3 + 2i, x2 = c(4:1, 2:5) - 5i) x[3, ] <- NA; x[4, 2] <- NA rowSums(x); colSums(x); rowMeans(x); colMeans(x)x1 x2 NA NAx1 x2 21+14i 21-30ix1 x2 3.0+2i 3.5-5i