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}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to