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]

