var                   package:base                   R Documentation

_C_o_v_a_r_i_a_n_c_e _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     `var' computes the variance of `x' and the covariance of `x' and
     `y' if `x' and `y' are vectors.  If `x' and `y' are matrices then
     the covariance between the columns of `x' and the the columns of
     `y' are computed.

_U_s_a_g_e:

     var(x, y = x, na.rm = FALSE, use)

_A_r_g_u_m_e_n_t_s:

       x: a numeric matrix or vector.

       y: a numeric matrix or vector.

   na.rm: logical.

     use: an optional character string giving a method for computing
          covariances in the presence of missing values.  This must be
          one of `"all.obs"', `"complete.obs"' or
          `"pairwise.complete.obs"', with abbreviation being permitted.

_D_e_t_a_i_l_s:

     If `na.rm' is `TRUE' then the complete observations (rows) are
     used to compute the variance.  If `na.rm' is `FALSE' and there are
     missing values, then `var' will fail.

     The argument `use' can also be used for describing how to handle
     missing values. Specifying `use = "all"' is equivalent to
     specifying `na.rm = FALSE' and specifying `use = "pair"' is
     equivalent to `na.rm = TRUE'. If `use = "pair"', then all the
     observations which are complete for a pair of variables are used
     to compute the covariance for that pair of variables. This can
     result in covariance matrices which are not positive semidefinite.

_S_e_e _A_l_s_o:

     `cov' with the same functionality for the multivariate case.

_E_x_a_m_p_l_e_s:

     var(1:10)# 9.166667

     var(1:5,1:5)# 2.5

