[R] Question with apply function

Steve Lianoglou mailinglist.honeypot at gmail.com
Thu Aug 6 02:59:38 CEST 2009


On Aug 5, 2009, at 5:45 PM, Noah Silverman wrote:

> In my continuing quest to generate some summary data, I've come  
> across some useful suggestions in pasts posts.
>
> The apply operation returns an error, and I can't figure out why.
>
> Can someone help me fix this?
>
> testlogdata <- cbind(testlogdata, range_group=cut(testlogdata 
> $lrm_score, breaks=c(.9, .8, .7, .6, .5, .4, .3, .2, .1)))
> apply(testlogdata, 2, function(x){tapply(x, list(testlogdata 
> $range_group), mean)})

I think you're close -- are you sure you should be making a list out  
of your testlogdata$range_group in your call to tapply?

Here's another way to kind of doing the same ... might need some  
tweaking, but:

apply(testlogdata, 2, function (x) lapply(split(x, testlogdata 
$range_group), mean)

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list