Skip to content

tapply and functions with more than one objects

2 messages · Dominic Roye, David Winsemius

#
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
#
On Jan 22, 2013, at 2:24 PM, Dominic Roye wrote:

            
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.