Re: [R] aggregate, by, *apply

2010-09-16 Thread Mark Ebbert
Thanks everyone for the responses. They were all helpful! On Sep 15, 2010, at 5:22 PM, Abhijit Dasgupta, PhD wrote: I would approach this slightly differently. I would make func a function of x and y. func - function(x,y){ m - median(x) return(m 2 m y) } Now generate tmp

[R] aggregate, by, *apply

2010-09-15 Thread Mark Ebbert
Dear R gurus, I regularly come across a situation where I would like to apply a function to a subset of data in a dataframe, but I have not found an R function to facilitate exactly what I need. More specifically, I'd like my function to have a context of where the data it's analyzing came

Re: [R] aggregate, by, *apply

2010-09-15 Thread Dennis Murphy
Hi: Try this: library(plyr) func - function(x, y) { m - median(x) if(m 2 m mean(y)) ret - TRUE else ret - FALSE ret } ddply(tmp, .(z), summarise, r = func(x, y)) z r 1 a FALSE 2 b TRUE 3 c TRUE HTH, Dennis On Wed, Sep 15, 2010 at 2:45 PM, Mark Ebbert

Re: [R] aggregate, by, *apply

2010-09-15 Thread David Winsemius
On Sep 15, 2010, at 5:45 PM, Mark Ebbert wrote: Dear R gurus, I regularly come across a situation where I would like to apply a function to a subset of data in a dataframe, but I have not found an R function to facilitate exactly what I need. More specifically, I'd like my function to

Re: [R] aggregate, by, *apply

2010-09-15 Thread Abhijit Dasgupta, PhD
I would approach this slightly differently. I would make func a function of x and y. func - function(x,y){ m - median(x) return(m 2 m y) } Now generate tmp just as you have. then: require(plyr) res - daply(tmp, .(z), summarise, res=func(x,y)) I believe this does the trick