[R] weighted.mean and tapply (again)

Berton Gunter gunter.berton at gene.com
Wed May 25 18:50:19 CEST 2005


> 
> In this simple case you can just coerce directly to a vector like so:
> 
> > foo <- by(dat, dat$GROUP, function(x) {weighted.mean(x$VALUE,
> x$FREQUENCY)})
> > bar <- as.vector(foo)
> 
> but look at the examples for ?by; in particular the use of 'sapply'.
> 
> Norm

As a general practice, I believe unlist() is preferable. ?unlist explains
why.

Cheers,
Bert Gunter




More information about the R-help mailing list