[R] Conversion of symmetry matrix into a vector
R. Michael Weylandt
michael.weylandt at gmail.com
Wed Nov 16 05:26:58 CET 2011
Try something like this:
X = matrix(rnorm(25), 5); colnames(X) <- rownames(X) <- letters[1:5]
Y <- dist(X)
On Tue, Nov 15, 2011 at 7:03 PM, ram basnet <basnetabc at yahoo.com> wrote:
> Dear R users,
> I am not good in R-language programming. So, i need your help.
> I want to convert my lower-triangle value of symmetry matrix into a vector with their row and column name.
> I found a function called "sm2vec" in "corpcor" package but it give only a vector of values but not row and column names. But i also want ROW and COLUMN name together with their corresponding values.
> To make more clear,
> For example: Suppose i have a symmetric matrix with lower-triangle value with 5 variables (eg. a - e). But in real, i have many variables.
> a b c d e
> a - - - - -
> b -0.44145 - - - -
> c -0.67922 0.232548 - - -
> d 0.114012 0.186583 0.244655 - -
> e -0.031 -0.35098 -0.16327 -0.34573 -
> Now, I want to convert above table into the following format. So, if some one can tell what kind of R code does this, it will be great help.
> row name column name value
> b a -0.44145
> c a -0.67922
> d a 0.114012
> e a -0.031
> c b 0.232548
> d b 0.186583
> e b -0.35098
> d c 0.244655
> e c -0.16327
> e d -0.34573
> If some one can help me, it will be great for me.
> Thanks in advance for your help.
> Ram Kumar Basnet
> Ph. D. student.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help