[R] Calculating all possible ratios

Rui Barradas ruipbarradas at sapo.pt
Sat May 12 18:28:16 CEST 2012


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, r-help-request at r-project.org escreveu:
> Date: Fri, 11 May 2012 12:39:23 -0700 (PDT)
> From: genome1976<genome1976 at hotmail.com>
> To:r-help at r-project.org
> Subject: [R] Calculating all possible ratios
> Message-ID:<1336765163039-4627405.post at n4.nabble.com>
> 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]]
>



More information about the R-help mailing list