[R] aggregate, by tapply

Agustin Lobo alobo at ija.csic.es
Thu Jan 24 11:54:02 CET 2002


In the case of *apply functions, the paramenters follow
the name of the function. I.e., if you want to compute a mean
with na.rm=T(which for one single vector would be
mean(mivector,na.rm=T), then

apply(mat,1,mean,na.rm=T)

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es


On Thu, 24 Jan 2002, Petr Pikal wrote:

> 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 at precheza.cz
> p.pik at 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 at 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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list