[R] Avoiding for-loops

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Thu Nov 25 19:54:20 CET 2004


On 25-Nov-04 John wrote:
> Hello R-users,
> 
> I have a symmetric matrix of numerical values and I
> want to obtain those values in the upper or lower
> triangle of the matrix in a vector. I tried to do the
> job by using two for-loops but it doens't seem to be a
> clever way, and I'd like to know a more efficient code
> for a large matrix of thousands of rows and columns.

The two functions uuper.tri and lower.tri do just this job!

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861  [NB: New number!]
Date: 25-Nov-04                                       Time: 18:54:20
------------------------------ XFMail ------------------------------




More information about the R-help mailing list