Rev 991 | Rev 1909 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{tcrossprod}\docType{methods}\alias{tcrossprod-methods}\alias{tcrossprod,dgCMatrix-method}\alias{tcrossprod,dgTMatrix-method}\alias{tcrossprod}\title{Cross-product of transpose}\description{Take the cross-product of the transpose of a matrix.This is formally equivalent to, but faster than, thecall \code{x \%*\% t(x)}.}\usage{tcrossprod(x)}\arguments{\item{x}{a matrix-like object}}\details{For some classes in the \code{Matrix} package, such as the\code{\link{dgCMatrix-class}}, it is much faster to calculate thecross-product of the transpose directly instead of calculating thetranspose first and then its cross-product.}\value{An object of an appropriate symmetric matrix class.}\section{Methods}{\describe{\item{x = "dgCMatrix"}{method for compressed, sparse,column-oriented matrices.}}}\seealso{\code{\link[base]{crossprod}}}\examples{## A random sparce "incidence" matrix :m <- matrix(0, 400, 500)set.seed(12)m[runif(314, 0, length(m))] <- 1mm <- as(m, "dgCMatrix")object.size(m) / object.size(mm) # smaller by a factor of 242.88## tcrossprod() is very fast:system.time(tCmm <- tcrossprod(mm))# "0" practicallysystem.time(cm <- crossprod(t(m))) #stopifnot(identical(cm, as(tCmm, "matrix")))## show "sparse" (sub) matrixtc <- cm[1:16, 1:30]storage.mode(tc) <- "character" ; tc[tc == "0"] <- "."dimnames(tc)[[2]] <- rep("", ncol(tc))noquote(tc)}\keyword{methods}\keyword{algebra}