Hi, I've looked through the posts but couldn't find a solution to this. I'd be really grateful if someone could help, I'd like to convert a data file of mutual information that is formatted as a matrix: TF1 TF2 TF3 TF200... Gene1 0.0 0.2 0.2 Gene2 1.4 0.0 2.8 Gene3 0.3 0.6 1.7 Gene6000.... To a list: Gene1 TF1 0.0 Gene1 TF2 0.2 Gene1 TF3 0.2 Gene2 TF1 1.4 Gene2 TF2 0.0 Gene2 TF3 2.8 Gene3 TF1 0.3 Gene3 TF2 0.6 Gene3 TF3 1.7 Gene6000...TF200...etc The matrix is ~6000X200 in size, Adam [[alternative HTML version deleted]]
Hi, Not sure how since I never use it, but I think melt() and then cast() from the reshape (or reshape2?) package are designed for this kind of transformations Ivan Le 11/19/2010 12:08, Adam Streline a ?crit :> Hi, I've looked through the posts but couldn't find a solution to this. I'd be > really grateful if someone could help, > > I'd like to convert a data file of mutual information that is formatted as > a matrix: > > TF1 TF2 TF3 TF200... > Gene1 0.0 0.2 0.2 > Gene2 1.4 0.0 2.8 > Gene3 0.3 0.6 1.7 > Gene6000.... > > To a list: > > Gene1 TF1 0.0 > Gene1 TF2 0.2 > Gene1 TF3 0.2 > Gene2 TF1 1.4 > Gene2 TF2 0.0 > Gene2 TF3 2.8 > Gene3 TF1 0.3 > Gene3 TF2 0.6 > Gene3 TF3 1.7 > Gene6000...TF200...etc > > The matrix is ~6000X200 in size, > > Adam > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > 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.-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
Hi: Look into melt() from package reshape2. Assuming m is your matrix, library(reshape2) meltm <- melt(m, id = rownames(m)) str(meltm) head(meltm) ## Toy example: m <- matrix(1:30, nrow = 3) rownames(m) <- paste('Gene', 1:nrow(m), sep = '') colnames(m) <- paste('T', 1:ncol(m), sep = '') m T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 Gene1 1 4 7 10 13 16 19 22 25 28 Gene2 2 5 8 11 14 17 20 23 26 29 Gene3 3 6 9 12 15 18 21 24 27 30 mm <- melt(m, id = rownames(m))> mmX1 X2 value 1 Gene1 T1 1 2 Gene2 T1 2 3 Gene3 T1 3 4 Gene1 T2 4 5 Gene2 T2 5 6 Gene3 T2 6 ...> str(mm)'data.frame': 30 obs. of 3 variables: $ X1 : Factor w/ 3 levels "Gene1","Gene2",..: 1 2 3 1 2 3 1 2 3 1 ... $ X2 : Factor w/ 10 levels "T1","T10","T2",..: 1 1 1 3 3 3 4 4 4 5 ... $ value: int 1 2 3 4 5 6 7 8 9 10 ... HTH, Dennis On Fri, Nov 19, 2010 at 3:08 AM, Adam Streline <astreline@yahoo.com> wrote:> Hi, I've looked through the posts but couldn't find a solution to this. I'd > be > really grateful if someone could help, > > I'd like to convert a data file of mutual information that is formatted as > a matrix: > > TF1 TF2 TF3 TF200... > Gene1 0.0 0.2 0.2 > Gene2 1.4 0.0 2.8 > Gene3 0.3 0.6 1.7 > Gene6000.... > > To a list: > > Gene1 TF1 0.0 > Gene1 TF2 0.2 > Gene1 TF3 0.2 > Gene2 TF1 1.4 > Gene2 TF2 0.0 > Gene2 TF3 2.8 > Gene3 TF1 0.3 > Gene3 TF2 0.6 > Gene3 TF3 1.7 > Gene6000...TF200...etc > > The matrix is ~6000X200 in size, > > Adam > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > >[[alternative HTML version deleted]]
Try this:> xTF1 TF2 TF3 Gene1 0.0 0.2 0.2 Gene2 1.4 0.0 2.8 Gene3 0.3 0.6 1.7 as.data.frame.table(as.matrix(x)) On Fri, Nov 19, 2010 at 9:08 AM, Adam Streline <astreline@yahoo.com> wrote:> Hi, I've looked through the posts but couldn't find a solution to this. I'd > be > really grateful if someone could help, > > I'd like to convert a data file of mutual information that is formatted as > a matrix: > > TF1 TF2 TF3 TF200... > Gene1 0.0 0.2 0.2 > Gene2 1.4 0.0 2.8 > Gene3 0.3 0.6 1.7 > Gene6000.... > > To a list: > > Gene1 TF1 0.0 > Gene1 TF2 0.2 > Gene1 TF3 0.2 > Gene2 TF1 1.4 > Gene2 TF2 0.0 > Gene2 TF3 2.8 > Gene3 TF1 0.3 > Gene3 TF2 0.6 > Gene3 TF3 1.7 > Gene6000...TF200...etc > > The matrix is ~6000X200 in size, > > Adam > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]