Matrix Cross Product

DESCRIPTION:

Returns a matrix which is the cross product of two given matrices, i.e., the matrix product of the transpose of the first matrix with the second.

USAGE:

crossprod(x)    # like crossprod(x, x) but faster
crossprod(x, y) 
x %c% y         # operator form 

REQUIRED ARGUMENTS:

x
matrix or vector, numeric or complex. Missing values (NA) are allowed.

OPTIONAL ARGUMENTS:

y
numeric or complex matrix or vector, having the same number of rows as x. Missing values (NA) are allowed.

VALUE:

matrix representing the cross product of x and y, defined as 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]).

DETAILS:

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.

SEE ALSO:

, , .

EXAMPLES:

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