crossprod {base} | R Documentation |
Given matrices x
and y
as arguments, return a matrix
cross-product. This is formally equivalent to (but usually slightly
faster than) the call t(x) %*% y
(crossprod
) or
x %*% t(y)
(tcrossprod
).
crossprod(x, y = NULL)
tcrossprod(x, y = NULL)
x , y |
numeric or complex matrices: |
A double or complex matrix, with appropriate dimnames
taken
from x
and y
.
When x
or y
are not matrices, they are treated as column or
row matrices, but their names
are usually not
promoted to dimnames
. Hence, currently, the last
example has empty dimnames.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
%*%
and outer product %o%
.
(z <- crossprod(1:4)) # = sum(1 + 2^2 + 3^2 + 4^2)
drop(z) # scalar
x <- 1:4; names(x) <- letters[1:4]; x
tcrossprod(as.matrix(x)) # is
identical(tcrossprod(as.matrix(x)),
crossprod(t(x)))
tcrossprod(x) # no dimnames