[R] Remark on tapply().
Rolf Turner
r.turner at auckland.ac.nz
Tue Dec 1 20:38:12 CET 2009
On 1/12/2009, at 8:32 PM, Karl Ove Hufthammer wrote:
<SNIP>
> Exercise to the reader:
>
> Note that
> sapply(split(x, ff, drop=TRUE), sum)
> gives you the values of (just) the non-empty levels.
>
> Now, why does
> sapply(split(x, ff), sum, drop=TRUE)
> give the wrong value (1) for these levels, while
> sapply(split(x, ff), sum, drop=FALSE)
> gives the the correct value?
>
> (The answer should be fairly obvious, but it's an easy mistake to
> make.)
That is ***CUTE***. I had to think long and hard to see what was
going on.
(But then I'm never very quick out of the blocks. :-) )
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list