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
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
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
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
4 matches
Mail list logo