crossprod(x) # like crossprod(x, x) but faster crossprod(x, y) x %c% y # operator form
t(x) %*% y
, where
%*%
is matrix
multiplication and
t
is transposition.
Thus the
[i,j]
th element of the result is
sum(x[,i]*y[,j])
.
It is better to use
crossprod(x)
than
crossprod(x, x)
.
This is faster, and on some machines is more accurate.
Any computation involving
NA
results in
NA
.
Vectors are taken to be columns, so
crossprod(vec1,vec2)
is a one by one
matrix with the element being the dot product of the two vectors.
amat <- matrix(c(19,8,11,2,18,17,15,19,10), nrow = 3) crossprod(amat) # if amat has dimmensions of n(rows) and p(cols) # the resultant matrix will be p by p bmat <- c(9, 5, 14) crossprod(amat, bmat) amat %c% bmat