[R] tapply and functions with more than one objects

2013-01-22 Thread Dominic Roye
Hello,

How i can use a costum function in tapply which has more than one variable?

I mean sum(x) only needs one object but what when i have a function
function(x,y) with more, how i indicate where are the other variables
to use?7


I hope someone can help me. Thank you!!

Best regards,

Dominic

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tapply and functions with more than one objects

2013-01-22 Thread David Winsemius

On Jan 22, 2013, at 2:24 PM, Dominic Roye wrote:

 Hello,
 
 How i can use a costum function in tapply which has more than one variable?
 
 I mean sum(x) only needs one object but what when i have a function
 function(x,y) with more, how i indicate where are the other variables
 to use?7

You can use:

lapply(split( multi_col_object, category_vec) , function(x,y){sum(x,y)}  ) 

aggregate(dat, category, FUN=sum)

Or:

do.call(rbind, by( multi_col_object, category_vec, function(x,y){ } )

Sometimes `Reduce` is more compact. Other times `mapply` is needed.
-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.