Skip to content
Prev 87244 / 398506 Next

subtotal, submean, aggregate

Yes, that must be it.  Probably best to issue a:

set.seed(1)

as part of the code when posting examples with random numbers.

Also here is a variation that uses rle that Roger used together with
some elements of the solution I posted:

runno <- with(rle(as.numeric(transect[,2])), rep(seq(along = lengths), lengths))
aggregate(transect[,1], list(obs = transect[,2], runno), sum)[,-2]
On 2/26/06, Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> wrote:
or negative. All that matters is whether its 0 or not.

In fact,
I posted
runno <- cumsum(c(TRUE,
runno2 <- cumsum(c(TRUE,
identical(runno, runno2) # TRUE


On
Actually the discrepancy you noticed remaining comes from
difference in
diff(as.numeric(transect[,2]))
One can work it around
makes:

runno <-
aggregate(transect[,1], list(obs =
I did not know about this use of diff,
cumsum for polishing. Really great and
Thanks a
Cheers,

Patrick


Gabor Grothendieck a ??crit :
Create another
runno <-
For
observations<-rpois(length(habitats),2)
transect<-data.frame(observations=observations,habitats=habitats)

aggregate()
forest 9
meadow 21
pasture 17

and
2 meadow 37
3 pasture 17

Did anybody hear about such a
Patrick

        
R-help at stat.math.ethz.ch
list
PLEASE do
http://www.R-project.org/posting-guide.html