EVOLUTION-MANAGER
Edit File: crossprod.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Matrix Crossproduct</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for crossprod {base}"><tr><td>crossprod {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Matrix Crossproduct</h2> <h3>Description</h3> <p>Given matrices <code>x</code> and <code>y</code> as arguments, return a matrix cross-product. This is formally equivalent to (but usually slightly faster than) the call <code>t(x) %*% y</code> (<code>crossprod</code>) or <code>x %*% t(y)</code> (<code>tcrossprod</code>). </p> <h3>Usage</h3> <pre> crossprod(x, y = NULL) tcrossprod(x, y = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, y</code></td> <td> <p>numeric or complex matrices (or vectors): <code>y = NULL</code> is taken to be the same matrix as <code>x</code>. Vectors are promoted to single-column or single-row matrices, depending on the context.</p> </td></tr> </table> <h3>Value</h3> <p>A double or complex matrix, with appropriate <code>dimnames</code> taken from <code>x</code> and <code>y</code>. </p> <h3>Note</h3> <p>When <code>x</code> or <code>y</code> are not matrices, they are treated as column or row matrices, but their <code><a href="names.html">names</a></code> are usually <b>not</b> promoted to <code><a href="dimnames.html">dimnames</a></code>. Hence, currently, the last example has empty dimnames. </p> <p>In the same situation, these matrix products (also <code><a href="matmult.html">%*%</a></code>) are more flexible in promotion of vectors to row or column matrices, such that more cases are allowed, since <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 3.2.0. </p> <p>The propagation of NaN/Inf values, precision, and performance of matrix products can be controlled by <code><a href="options.html">options</a>("matprod")</code>. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="matmult.html">%*%</a></code> and outer product <code><a href="outer.html">%o%</a></code>. </p> <h3>Examples</h3> <pre> (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 m <- matrix(1:6, 2,3) ; v <- 1:3; v2 <- 2:1 stopifnot(identical(tcrossprod(v, m), v %*% t(m)), identical(tcrossprod(v, m), crossprod(v, t(m))), identical(crossprod(m, v2), t(m) %*% v2)) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>