Re: [R] Remark on tapply().

2009-12-01 Thread Rolf Turner
On 1/12/2009, at 8:32 PM, Karl Ove Hufthammer wrote: 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 sa

Re: [R] Remark on tapply().

2009-11-30 Thread Karl Ove Hufthammer
On Tue, 1 Dec 2009 14:10:17 +1300 Rolf Turner wrote: > Consider the following: > > > set.seed(42) > > ff <- factor(sample(c(1,3,5),42,TRUE),levels=1:5) > > x <- runif(42) > > tapply(x,ff,sum) > 12345 > 3.675436 NA 7.519675 NA 9.094210 > >

[R] Remark on tapply().

2009-11-30 Thread Rolf Turner
Consider the following: > set.seed(42) > ff <- factor(sample(c(1,3,5),42,TRUE),levels=1:5) > x <- runif(42) > tapply(x,ff,sum) 12345 3.675436 NA 7.519675 NA 9.094210 I got bitten by those NAs in the result of tapply(). Effectively one is summi