Hello, I'm glad it helped. Now to make the result readable. (I had thought of it.)
pairwise.ratios <- function(x, prefix="probeset", char=":"){ n <- ncol(x) cn <- colnames(x) if(length(cn) == 0){ cn <- gsub(" ", "0", formatC(seq.int(n), width=nchar(n))) cn <- paste(prefix, cn, sep="") } cmb <- combn(n, 2) r1 <- apply(cmb, 2, function(j) x[, j[1]]/x[, j[2]]) r2 <- apply(cmb, 2, function(j) x[, j[2]]/x[, j[1]]) colnames(r1) <- apply(cmb, 2, function(j) paste(cn[j], collapse=char)) colnames(r2) <- apply(cmb, 2, function(j) paste(cn[rev(j)], collapse=char)) cbind(r1, r2)[, order(c(colnames(r1), colnames(r2)))] } m1 <- matrix(1:24, ncol=6) pairwise.ratios(m1) Rui Barradas genome1976 wrote > > Thanks so much Rui. I really appreciate all the help. > > I implemented the code and it ran fine. I was wondering how I could > include the probeset ids as probeset1:probeset2 in the final output so > that I know which ratios are for which probeset pairs. > > > Thanks so much. > Som. > Date: Sat, 12 May 2012 09:29:54 -0700 > From: ml-node+s789695n4629105h16@.nabble > To: genome1976@ > Subject: Re: Calculating all possible ratios > > > > Hello, > > > If by all possible gene ratios you mean all pairwise column ratios, try > > the following. > > > # Make up some data > > x <- matrix(1:24, ncol=6) > > > cmb <- combn(ncol(x), 2) > > r1 <- apply(cmb, 2, function(j) x[, j[1]]/x[, j[2]]) > > r2 <- apply(cmb, 2, function(j) x[, j[2]]/x[, j[1]]) > > cbind(r1, r2) > > > Note that the dataset must be a numeric only matrix or data.frame. > > > Hope this helps, > > > Rui Barradas > > > Em 12-05-2012 11:00, [hidden email] escreveu: > >> Date: Fri, 11 May 2012 12:39:23 -0700 (PDT) > >> From: genome1976<[hidden email]> > >> To:[hidden email] > >> Subject: [R] Calculating all possible ratios > >> Message-ID:<[hidden email]> > >> Content-Type: text/plain > >> > >> I have a data matrix with genes as columns and samples as rows. I want >> to > >> create all possible gene ratios.Is there an elegant and fast way to do it >> in > >> R and write it to a dataframe? > >> > >> Thanks for any help. > >> Som. > >> > >> -- > >> View this message in >> context:http://r.789695.n4.nabble.com/Calculating-all-possible-ratios-tp4627405.html >> Sent from the R help mailing list archive at Nabble.com. > >> [[alternative HTML version deleted]] > >> > > ______________________________________________ > > [hidden email] 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. > > > > > > > > > > If you reply to this email, your message will be added to the > discussion > below: > > http://r.789695.n4.nabble.com/Calculating-all-possible-ratios-tp4627405p4629105.html > > > > To unsubscribe from Calculating all possible ratios, click here. > > NAML > -- View this message in context: http://r.789695.n4.nabble.com/Calculating-all-possible-ratios-tp4627405p4629513.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.