[R] tapply and more than one function, with different arguments

2010-01-26 Thread RINNER Heinrich
Dear R-users, I am working with R version 2.10.1. Say I have is a simple function like this: my.fun - function(x, mult) mult*sum(x) Now, I want to apply this function along with some other (say 'max') to a simple data.frame, like: dat - data.frame(x = 1:4, grp = c(a,a,b,b)) Ideally, the

Re: [R] tapply and more than one function, with different arguments

2010-01-26 Thread Peter Ehlers
Try replacing 'max' with 'mean' and see what you get. Then have a look at ?max and see what max() does with extra arguments. I'm not sure it's relevant, but it might be useful to check what Hmisc::summarize does. -Peter Ehlers RINNER Heinrich wrote: Dear R-users, I am working with R version

Re: [R] tapply and more than one function, with different arguments

2010-01-26 Thread Dennis Murphy
Hi: Using the plyr package, we can get the result as follows: library(plyr) my.fun - function(x, mult) mult*sum(x) dat - data.frame(x = 1:4, grp = c(a,a,b,b)) ddply(dat, .(grp), summarize, max = max(x), myfun = my.fun(x, 10)) grp max myfun 1 a 230 2 b 470 HTH, Dennis On

Re: [R] tapply and more than one function, with different arguments

2010-01-26 Thread RINNER Heinrich
Hi Dennis, now that's a very nice function, and this seems to be just what I need! Thanks a lot! -Heinrich. Von: Dennis Murphy [djmu...@gmail.com] Gesendet: Dienstag, 26. Januar 2010 19:44 An: RINNER Heinrich Cc: r-help Betreff: Re: [R] tapply and more than