[R] tapply with unequal length of arguments

Uwe Ligges ligges at statistik.uni-dortmund.de
Sun Mar 12 14:58:02 CET 2006

Stefanie von Felten, IPW&IfU wrote:

> Hi everyone,
> Is it possible to use tapply(x,y,mean) if not all groups of x by y are 
> of the same length (for example if you have one missing observation)?
> I tried tapply(x,y,mean,na.omit=T) but it doesn't work!

See ?tapply which tells you that the argument "..." is passed to FUN 
which is mean() in this case. mean() has an argument "na.rm", see ?mean.
So we get:

  tapply(x, y, mean, na.rm = TRUE)

Please read the help pages more carefully.

Uwe Ligges

> Steffi

More information about the R-help mailing list