\Header{lower.to.upper.tri.inds}{Permute Indices for Triangular Matrices}
\alias{upper.to.lower.tri.inds}{lower.to.upper.tri.inds}
\keyword{array}{lower.to.upper.tri.inds}
\keyword{utilities}{lower.to.upper.tri.inds}
\begin{Description}\relax
Compute index vectors for extracting or reordering of lower or upper
triangular matrices that are stored as contiguous vectors.
\end{Description}
\begin{Usage}
\begin{verbatim}
lower.to.upper.tri.inds(n)
upper.to.lower.tri.inds(n)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{n}] integer larger than 1.
\end{ldescription}
\end{Arguments}
\begin{Value}
integer vector containing a permutation of \code{1:N} where
\eqn{N = n(n-1)/2}{}.
\end{Value}
\begin{Note}\relax
these functions are mainly for internal use in the cluster package,
and may not remain available (unless we see a good reason).
\end{Note}
\begin{SeeAlso}\relax
\code{\Link{upper.tri}}, \code{\Link{lower.tri}} with a related
purpose.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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)
\end{ExampleCode}
\end{Examples}

