lower.to.upper.tri.inds       package:cluster       R Documentation

_P_e_r_m_u_t_e _I_n_d_i_c_e_s _f_o_r _T_r_i_a_n_g_u_l_a_r _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Compute index vectors for extracting or reordering of lower or
     upper triangular matrices that are stored as contiguous vectors.

_U_s_a_g_e:

     lower.to.upper.tri.inds(n)
     upper.to.lower.tri.inds(n)

_A_r_g_u_m_e_n_t_s:

       n: integer larger than 1.

_V_a_l_u_e:

     integer vector containing a permutation of '1:N' where N =
     n(n-1)/2.

_N_o_t_e:

     these functions are mainly for internal use in the cluster
     package, and may not remain available (unless we see a good
     reason).

_S_e_e _A_l_s_o:

     'upper.tri', 'lower.tri' with a related purpose.

_E_x_a_m_p_l_e_s:

     m5 <- matrix(NA,5,5)
     m <- m5; m[lower.tri(m)] <- upper.to.lower.tri.inds(5); m
     m <- m5; m[upper.tri(m)] <- lower.to.upper.tri.inds(5); m

     stopifnot(lower.to.upper.tri.inds(2) == 1,
               lower.to.upper.tri.inds(3) == 1:3,
               upper.to.lower.tri.inds(3) == 1:3,
          sort(upper.to.lower.tri.inds(5)) == 1:10,
          sort(lower.to.upper.tri.inds(6)) == 1:15)

