tcrossprod              package:Matrix              R Documentation

_C_r_o_s_s-_p_r_o_d_u_c_t _o_f _t_r_a_n_s_p_o_s_e

_D_e_s_c_r_i_p_t_i_o_n:

     Take the cross-product of the transpose of a matrix.
     'tcrossprod(x)' is formally equivalent to, but faster than, the
     call 'x %*% t(x)', and so is 'tcrossprod(x, y)' instead of 'x %*%
     t(y)'.

_U_s_a_g_e:

     tcrossprod(x, y = NULL)

_A_r_g_u_m_e_n_t_s:

       x: a matrix-like object

       y: a matrix-like object or 'NULL' (by default); the latter case
          is formally equivalent to 'y = x'.

_D_e_t_a_i_l_s:

     For some classes in the 'Matrix' package, such as 'dgCMatrix', it
     is much faster to calculate the cross-product of the transpose
     directly instead of calculating the transpose first and then its
     cross-product.

_V_a_l_u_e:

     An object of an appropriate symmetric matrix class.

_M_e_t_h_o_d_s:


     _x = "_d_g_C_M_a_t_r_i_x" method for compressed, sparse, column-oriented
          matrices.

_S_e_e _A_l_s_o:

     'crossprod'

_E_x_a_m_p_l_e_s:

      ## A random sparce "incidence" matrix :
      m <- matrix(0, 400, 500)
      set.seed(12)
      m[runif(314, 0, length(m))] <- 1
      mm <- as(m, "dgCMatrix")
      object.size(m) / object.size(mm) # smaller by a factor of > 200

      ## tcrossprod() is very fast:
      system.time(tCmm <- tcrossprod(mm))# 0   (PIII, 933 MHz)
      system.time(cm <- crossprod(t(m))) # 0.16
      system.time(cm. <- tcrossprod(m))  # 0.02

      stopifnot(cm == as(tCmm, "matrix"))

      ## show sparse sub matrix
      tCmm[1:16, 1:30]

