crossprod                package:base                R Documentation

_M_a_t_r_i_x _C_r_o_s_s_p_r_o_d_u_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     Given matrices 'x' and 'y' as arguments, return a matrix
     cross-product.  This is formally equivalent to (but usually
     slightly faster than) the call 't(x) %*% y' ('crossprod') or 'x
     %*% t(y)' ('tcrossprod').

_U_s_a_g_e:

     crossprod(x, y = NULL)

     tcrossprod(x, y = NULL)

_A_r_g_u_m_e_n_t_s:

    x, y: numeric or complex matrices: 'y = NULL' is taken to be the
          same matrix as 'x'.  Vectors are promoted to single-column
          matrices.

_V_a_l_u_e:

     A double or complex matrix, with appropriate 'dimnames' taken from
     'x' and 'y'.

_N_o_t_e:

     When 'x' or 'y' are not matrices, they are treated as column or
     row matrices, but their 'names' are usually *not* promoted to
     'dimnames'.  Hence, currently, the last example has empty
     dimnames.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     '%*%' and outer product '%o%'.

_E_x_a_m_p_l_e_s:

     (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

