[R] Vectorize tapply(...,cumsum) output

Gerrit Draisma g.draisma at erasmusmc.nl
Wed Apr 9 14:53:41 CEST 2008


I would like to graph cumulative counts
and use tapply(...,cumsum) to get
the cumulative counts.
For instance:
    library(lattice)
    t<-rep(1:4,each=3)    #time
    i<-rep(1:3,times=4)   #categories
    n<-rpois(length(t),t) #count
    xyplot(n ~ t,groups=i,
    type="o",key=simpleKey(as.character(1:3),x=0,y=1,lines=T))
    N<-tapply(n,t,cumsum)

Now, what is the best way to convert N
to a vector that can be plotted?
E.g.
    xyplot(N ~ t,groups=i,
    type="o",key=simpleKey(as.character(1:3),x=0,y=1,lines=T))

Or is there a better way to get cumulative graphs?

Thanks,
Gerrit.



More information about the R-help mailing list