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

