Message-ID: <20512299.1075841472299.JavaMail.evans@thyme> Date: Thu, 24 Jan 2002 01:44:17 -0800 (PST) From: vito.muggeo@giustizia.it To: petr.pikal@precheza.cz, r-help@stat.math.ethz.ch Subject: Re: [R] aggregate, by tapply Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-From: "vito muggeo" X-To: Petr Pikal , r-help@stat.math.ethz.ch X-cc: X-bcc: X-Folder: \ExMerge - Richey, Cooper\R X-Origin: RICHEY-C X-FileName: cooper richey 6-26-02.PST Hi Petr, probably I don't understand correctly your question. However you can write any function with several arguments (input variables) and after use tapply. That is: fn<-function(arg1, arg2, arg3, ....){....} tapply(arg1, factor, fn, arg2, arg3,....) Furthermore you can you the three dots "..." to pass any argument in the functions in your fn() Hope this helps you! vito ----- Original Message ----- From: "Petr Pikal" To: Sent: Thursday, January 24, 2002 7:56 AM Subject: [R] aggregate, by tapply > Dear R users > > I searched some sources but i did not find an answer.Please give > me some hint to following problem. > > I would like to compute a summary statistic for some vector for > different factor levels. I know I can use tapply or aggregate but I > do not know if there is a way how to use function with several > (two) variable input (like weighted.mean). > > I wrote a simple a function for factor weighted mean > fff<-function(x,fact,w) > { > ws<-tapply(w,fact,sum) > newx<-x*w > tapply(newx,fact,sum)/ws > } > > which can handle particular case but does exist some more general > solution how to use FUN(X1,X2) in aggregation procedures > (tapply, aggregate, by) directly? > > Thank you > Petr Pikal > petr.pikal@precheza.cz > p.pik@volny.cz > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._