[R] convering upper triangular matrix into vector

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Oct 2 12:16:52 CEST 2005


e.rapsomaniki at mail.cryst.bbk.ac.uk writes:

> Hi
> 
> I have two symmetrical distance matrices and want to compute the correlation
> coefficient between them (after turning them into vectors). 
> 
> Is there a way of selecting only the upper triangular part of each matrix, then
> convert this into a vector so I can compute the correlation?

X[upper.tri(X)]

(as help.search("triangular") would have told you soon enough)

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list