EVOLUTION-MANAGER
Edit File: Matrix-class.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: Virtual Class "Matrix" Class of Matrices</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 Matrix-class {Matrix}"><tr><td>Matrix-class {Matrix}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Virtual Class "Matrix" Class of Matrices</h2> <h3>Description</h3> <p>The <code>Matrix</code> class is a class contained by all actual classes in the <span class="pkg">Matrix</span> package. It is a “virtual” class. </p> <h3>Slots</h3> <p>Common to <em>all</em> matrix objects in the package: </p> <dl> <dt><code>Dim</code>:</dt><dd><p>Object of class <code>"integer"</code> - the dimensions of the matrix - must be an integer vector with exactly two non-negative values.</p> </dd> <dt><code>Dimnames</code>:</dt><dd><p>list of length two; each component containing NULL or a <code><a href="../../base/html/character.html">character</a></code> vector length equal the corresponding <code>Dim</code> element.</p> </dd> </dl> <h3>Methods</h3> <dl> <dt>determinant</dt><dd><p><code>signature(x = "Matrix", logarithm = "missing")</code>: and</p> </dd> <dt>determinant</dt><dd><p><code>signature(x = "Matrix", logarithm = "logical")</code>: compute the (<i>\log</i>) determinant of <code>x</code>. The method chosen depends on the actual Matrix class of <code>x</code>. Note that <code><a href="../../base/html/det.html">det</a></code> also works for all our matrices, calling the appropriate <code>determinant()</code> method. The <code>Matrix::det</code> is an exact copy of <code>base::det</code>, but in the correct namespace, and hence calling the S4-aware version of <code>determinant()</code>.).</p> </dd> <dt>diff</dt><dd><p><code>signature(x = "Matrix")</code>: As <code><a href="../../base/html/diff.html">diff</a>()</code> for traditional matrices, i.e., applying <code>diff()</code> to each column.</p> </dd> <dt>dim</dt><dd><p><code>signature(x = "Matrix")</code>: extract matrix dimensions <code><a href="../../base/html/dim.html">dim</a></code>.</p> </dd> <dt>dim<-</dt><dd><p><code>signature(x = "Matrix", value = "ANY")</code>: where <code>value</code> is integer of length 2. Allows to <em>reshape</em> Matrix objects, but only when <code>prod(value) == prod(dim(x))</code>.</p> </dd> <dt>dimnames</dt><dd><p><code>signature(x = "Matrix")</code>: extract <code><a href="../../base/html/dimnames.html">dimnames</a></code>.</p> </dd> <dt>dimnames<-</dt><dd><p><code>signature(x = "Matrix", value = "list")</code>: set the <code>dimnames</code> to a <code><a href="../../base/html/list.html">list</a></code> of length 2, see <code><a href="../../base/html/dimnames.html">dimnames<-</a></code>.</p> </dd> <dt>length</dt><dd><p><code>signature(x = "Matrix")</code>: simply defined as <code>prod(dim(x))</code> (and hence of mode <code>"double"</code>).</p> </dd> <dt>show</dt><dd><p><code>signature(object = "Matrix")</code>: <code><a href="../../methods/html/show.html">show</a></code> method for <code><a href="../../base/html/print.html">print</a></code>ing. For printing <em>sparse</em> matrices, see <code><a href="printSpMatrix.html">printSpMatrix</a></code>.</p> </dd> <dt>image</dt><dd><p><code>signature(object = "Matrix")</code>: draws an <code><a href="../../graphics/html/image.html">image</a></code> of the matrix entries, using <code><a href="../../lattice/html/levelplot.html">levelplot</a>()</code> from package <span class="pkg">lattice</span>.</p> </dd> <dt>head</dt><dd><p><code>signature(object = "Matrix")</code>: return only the <em>“head”</em>, i.e., the first few rows.</p> </dd> <dt>tail</dt><dd><p><code>signature(object = "Matrix")</code>: return only the <em>“tail”</em>, i.e., the last few rows of the respective matrix.</p> </dd> </dl> <p><br /> </p> <dl> <dt>as.matrix, as.array</dt><dd><p><code>signature(x = "Matrix")</code>: the same as <code>as(x, "matrix")</code>; see also the note below.</p> </dd> <dt>as.vector</dt><dd><p><code>signature(x = "Matrix", mode = "missing")</code>: <code>as.vector(m)</code> should be identical to <code>as.vector(as(m, "matrix"))</code>, implemented more efficiently for some subclasses.</p> </dd> <dt>as(x, "vector"), as(x, "numeric")</dt><dd><p>etc, similarly.</p> </dd> <dt>coerce</dt><dd><p><code>signature(from = "ANY", to = "Matrix")</code>: This relies on a correct <code><a href="../../base/html/matrix.html">as.matrix</a>()</code> method for <code>from</code>.</p> </dd> </dl> <p>There are many more methods that (conceptually should) work for all <code>"Matrix"</code> objects, e.g., <code><a href="colSums.html">colSums</a></code>, <code><a href="colSums.html">rowMeans</a></code>. Even <span class="pkg">base</span> functions may work automagically (if they first call <code><a href="../../base/html/matrix.html">as.matrix</a>()</code> on their principal argument), e.g., <code><a href="../../base/html/apply.html">apply</a></code>, <code><a href="../../base/html/eigen.html">eigen</a></code>, <code><a href="../../base/html/svd.html">svd</a></code> or <code><a href="../../base/html/kappa.html">kappa</a></code> all do work via coercion to a “traditional” (dense) <code><a href="../../base/html/matrix.html">matrix</a></code>. </p> <h3>Note</h3> <p>Loading the <code>Matrix</code> namespace “overloads” <code><a href="../../base/html/matrix.html">as.matrix</a></code> and <code><a href="../../base/html/array.html">as.array</a></code> in the <span class="pkg">base</span> namespace by the equivalent of <code>function(x) as(x, "matrix")</code>. Consequently, <code>as.matrix(m)</code> or <code>as.array(m)</code> will properly work when <code>m</code> inherits from the <code>"Matrix"</code> class — <em>also</em> for functions in package <span class="pkg">base</span> and other packages. E.g., <code><a href="../../base/html/apply.html">apply</a></code> or <code><a href="../../base/html/outer.html">outer</a></code> can therefore be applied to <code>"Matrix"</code> matrices. </p> <h3>Author(s)</h3> <p>Douglas Bates <a href="mailto:bates@stat.wisc.edu">bates@stat.wisc.edu</a> and Martin Maechler</p> <h3>See Also</h3> <p>the classes <code><a href="dgeMatrix-class.html">dgeMatrix</a></code>, <code><a href="dgCMatrix-class.html">dgCMatrix</a></code>, and function <code><a href="Matrix.html">Matrix</a></code> for construction (and examples). </p> <p>Methods, e.g., for <code><a href="kronecker-methods.html">kronecker</a></code>. </p> <h3>Examples</h3> <pre> slotNames("Matrix") cl <- getClass("Matrix") names(cl@subclasses) # more than 40 .. showClass("Matrix")#> output with slots and all subclasses (M <- Matrix(c(0,1,0,0), 6, 4)) dim(M) diag(M) cm <- M[1:4,] + 10*Diagonal(4) diff(M) ## can reshape it even : dim(M) <- c(2, 12) M stopifnot(identical(M, Matrix(c(0,1,0,0), 2,12)), all.equal(det(cm), determinant(as(cm,"matrix"), log=FALSE)$modulus, check.attributes=FALSE)) </pre> <hr /><div style="text-align: center;">[Package <em>Matrix</em> version 1.2-17 <a href="00Index.html">Index</a>]</div> </body></html>