[BioC] Average based on group

Fabrice Tourre fabrice.ciup at gmail.com
Thu May 12 18:08:32 CEST 2011


I think this is not what I want.

aggregate(MyData[,4],MyData[,2],mean)
tapply(MyData[,4],MyData[,2],mean)

cannot for my purpose.

The return value is a vector of 10.

On Thu, May 12, 2011 at 5:51 PM, Achilleas Pitsillides
<anp4r at virginia.edu> wrote:
> Hi,
> Assuming I understood the question correctly  you can use the "by" function
> from the base package i.e:
> by(MyData[,4],MyData[,2],mean)
> where the factor is in the second column and the numerical data is in the
> fourth column.
> cheers,
> Achilleas
>
> On Thu, May 12, 2011 at 11:20 AM, Fabrice Tourre <fabrice.ciup at gmail.com>wrote:
>
>> Dear list,
>> I have dataframe, the second column is groups factor, each group has
>> 10 items. The data as fellow.
>> chr10   rs9971029   71916552    0.1
>> chr10   rs9971029   71916553    0.4
>> chr10   rs9971029   71916554    0.3
>> chr10   rs9971029   71916555    0.9
>> chr10   rs9971029   71916556    1
>> chr10   rs9971029   71916557    2
>> chr10   rs9971029   71916558    4
>> chr10   rs9971029   71916559    0.8
>> chr10   rs9971029   71916560    0.9
>> chr10   rs9971029   71916561    0.8
>> chr10   rs9971030   71916726    0.6
>> chr10   rs9971030   71916727    0.5
>> chr10   rs9971030   71916728    0.4
>> chr10   rs9971030   71916729    0.7
>> chr10   rs9971030   71916730    0
>> chr10   rs9971030   71916731    0
>> chr10   rs9971030   71916732    0.6
>> chr10   rs9971030   71916733    0.8
>> chr10   rs9971030   71916734    0.9
>> chr10   rs9971030   71916735    1
>>
>> I want to get a average of each item based on the group factor. So at
>> last I want to get a vector which length is 10.
>> The value calculated as this:
>>
>> (0.1+0.6)/2
>> (0.4+0.5)/2
>>>> (0.8+1)/2
>>
>> Thank you very much in advance.
>>
>> _______________________________________________
>> Bioconductor mailing list
>> Bioconductor at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives:
>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>



More information about the Bioconductor mailing list