How do I convert the output of cor(x) to a columnar format?
Ex. from format below
X Y Z
X 1.0 0.9 0.5
Y 0.9 1.0 0.1
Z 0.5 0.1 1.0
to format below
X X 1.0
X Y 0.9
X Z 0.5
Y X 0.9
Y Y 1.0
Y Z 0.1
Z X 0.5
Z Y 0.1
Z Z 1.0
Thanks!
Omer
Omer Bakkalbasi wrote:> How do I convert the output of cor(x) to a columnar format? > Ex. from format below > X Y Z > X 1.0 0.9 0.5 > Y 0.9 1.0 0.1 > Z 0.5 0.1 1.0 > > to format below > > X X 1.0 > X Y 0.9 > X Z 0.5 > Y X 0.9 > Y Y 1.0 > Y Z 0.1 > Z X 0.5 > Z Y 0.1 > Z Z 1.0See, e.g., ?reshape Uwe Ligges> Thanks! > > Omer > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Maybe like:
> dat
X Y Z
X 1.0 0.9 0.5
Y 0.9 1.0 0.1
Z 0.5 0.1 1.0
> datrow <- stack(as.data.frame(dat))
> datrow$X=rownames(dat)
> datrow
values ind X
1 1.0 X X
2 0.9 X Y
3 0.5 X Z
4 0.9 Y X
5 1.0 Y Y
6 0.1 Y Z
7 0.5 Z X
8 0.1 Z Y
9 1.0 Z Z
>
Regards,
Muhammad Subianto
On this day 6/17/2005 8:14 AM, Omer Bakkalbasi wrote:> How do I convert the output of cor(x) to a columnar format?
> Ex. from format below
> X Y Z
> X 1.0 0.9 0.5
> Y 0.9 1.0 0.1
> Z 0.5 0.1 1.0
>
> to format below
>
> X X 1.0
> X Y 0.9
> X Z 0.5
> Y X 0.9
> Y Y 1.0
> Y Z 0.1
> Z X 0.5
> Z Y 0.1
> Z Z 1.0
>
> Thanks!
>
> Omer
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
Something like:> dat <- data.frame(x=runif(10), y=runif(10), z=runif(10)) > m <- cor(dat) > mx y z x 1.0000000 0.1183305 0.1096394 y 0.1183305 1.0000000 -0.2819285 z 0.1096394 -0.2819285 1.0000000> mat2col <- function(m) {+ m2 <- matrix(m, ncol=1) + rownames(m2) <- outer(rownames(m), colnames(m), paste) + m2 + }> mat2col(m)[,1] x x 1.0000000 y x 0.1183305 z x 0.1096394 x y 0.1183305 y y 1.0000000 z y -0.2819285 x z 0.1096394 y z -0.2819285 z z 1.0000000 Andy> From: Omer Bakkalbasi > > How do I convert the output of cor(x) to a columnar format? > Ex. from format below > X Y Z > X 1.0 0.9 0.5 > Y 0.9 1.0 0.1 > Z 0.5 0.1 1.0 > > to format below > > X X 1.0 > X Y 0.9 > X Z 0.5 > Y X 0.9 > Y Y 1.0 > Y Z 0.1 > Z X 0.5 > Z Y 0.1 > Z Z 1.0 > > Thanks! > > Omer > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >