[R] function 2 convert matrix to long-format?

arun smartpink111 at yahoo.com
Wed Jul 24 15:02:58 CEST 2013


Hi,
It is better to use ?dput().
a1<-array(c(0.1416,0.1049,0.1328,0.12235,0.11890,0.15510,0.14225,0.09295,0.13350,0.16875,0.09900,0.14560),c(3,2,2))
 dimnames(a1)<- list(c("T0","T1","T2"),c("B6","B9"),c("minus","plus"))
library(plyr)
library(reshape2)
res<-melt(adply(a1,c(1,2)),id.vars=c("X1","X2"))


res
#   X1 X2 variable   value
#1  T0 B6    minus 0.14160
#2  T1 B6    minus 0.10490
#3  T2 B6    minus 0.13280
#4  T0 B9    minus 0.12235
#5  T1 B9    minus 0.11890
#6  T2 B9    minus 0.15510
#7  T0 B6     plus 0.14225
#8  T1 B6     plus 0.09295
#9  T2 B6     plus 0.13350
#10 T0 B9     plus 0.16875
#11 T1 B9     plus 0.09900
#12 T2 B9     plus 0.14560
A.K.



----- Original Message -----
From: Witold E Wolski <wewolski at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Wednesday, July 24, 2013 6:00 AM
Subject: [R] function 2 convert matrix to long-format?

I would like to convert this (output of tapply)
, , minus

       B6      S9
T0 0.1416 0.12235
T1 0.1049 0.11890
T2 0.1328 0.15510

, , plus

        B6      S9
T0 0.14225 0.16875
T1 0.09295 0.09900
T2 0.13350 0.14560

to long-format :

T0 B6 minus 0.1416
T0 S9 minus 0.12235
T0 B6 plus 0.14225
T0 S9 plus 0.16875
....
...


whats the default way in R?

best




--
Witold Eryk Wolski

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 mailing list