[R] aggregating data

Oscar Perpiñan Lamigueiro oscar.perpinan at upm.es
Thu Jun 30 14:38:32 CEST 2011


Hi,

You can get it with "by":

foo <- function(x)c(length(x$probe), mean(x$exp))
res <- by(df[c('exp', 'probe')], df['gene'], FUN=foo)
do.call(rbind, res)

Bye,

Oscar.


-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

El Thu, 30 Jun 2011 17:28:02 +1000
Max Mariasegaram <max.mariasegaram at qut.edu.au> escribió:
> Hi,
> 
> I am interested in using the cast function in R to perform some
> aggregation. I did once manage to get it working, but have now
> forgotten how I did this. So here is my dilemma. I have several
> thousands of probes (about 180,000) corresponding to each gene; what
> I'd like to do is obtain is a frequency count of the various
> occurrences of each probes for each gene.
> 
> The data would look something like this:
> 
> Gene     ProbeID               Expression_Level
> A             1              0.34
> A             2              0.21
> E              3              0.11
> A             4              0.21
> F              5              0.56
> F              6              0.87
> .
> .
> .
> (180000 data points)
> 
> In each case, the probeID is unique. The output I am looking for is
> something like this:
> 
> Gene     No.ofprobes      Mean_expression
> A             3              0.25
> 
> Is there an easy way to do this using "cast" or "melt"? Ideally, I
> would also like to see the unique probes corresponding to each gene
> in the wide format.
> 
> Thanks in advance
> Max
> 
> Maxy Mariasegaram| Reserach Fellow | Australian Prostate Cancer
> Research Centre| Level 1, Building 33 | Princess Alexandra Hospital |
> 199 Ipswich Road, Brisbane QLD 4102 Australia | t: 07 3176 3073| f:
> 07 3176 7440 | e: mariaseg at qut.edu.au
> 
> 
> 	[[alternative HTML version deleted]]
> 



More information about the R-help mailing list