[BioC] average replicate columns in a matrix

Gordon K Smyth smyth at wehi.EDU.AU
Tue Mar 29 00:08:48 CEST 2011


Dear Wendy,

The function avearrays() in the limma package does exactly this:

   > library(limma)
   > avearrays(test)
          A  B
   [1,] 2.5 10
   [2,] 3.5 11
   [3,] 4.5 12

Best wishes
Gordon

> Date: Sun, 27 Mar 2011 19:25:29 -0400
> From: Wendy Qiao <wendy2.qiao at gmail.com>
> To: bioconductor at r-project.org
> Subject: [BioC] average replicate columns in a matrix
> Message-ID:
> 	<AANLkTin7ZkTsaX4+T+X0zNMARYzzNG2kBtxxA-d-98db at mail.gmail.com>
> Content-Type: text/plain
>
> I have a matrix like following
>
>> test=matrix(c(1:15),nrow=3,ncol=5)
>> colnames(test)=c("A","A","B","B","B")
>> test
>     A A B  B  B
> [1,] 1 4 7 10 13
> [2,] 2 5 8 11 14
> [3,] 3 6 9 12 15
>
> I want to calculate the average of each replicates, ie. I want the output to
> be
>     A B
> [1,] 2.5 10
> [2,] 3.5 11
> [3,] 4.5 12
>
> I can do this by looping through each level of the column name, but I was
> wondering if there is a function for calculating the average of replicates
> in one step.
>
> Thank you in advance.
> Wendy

______________________________________________________________________
The information in this email is confidential and intend...{{dropped:4}}



More information about the Bioconductor mailing list