[R] Statemement by recurrence avoiding loop
Anders Nielsen
anielsen at dina.kvl.dk
Mon Jul 8 10:32:10 CEST 2002
Hi Tristan
I think the following solves most of your
problem
Kind regards,
Anders.
> x<-matrix(1:9,3)
> apply(x,2,cumsum)
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 3 9 15
[3,] 6 15 24
On Mon, 2002-07-08 at 09:47, tlorino at vet-alfort.fr wrote:
> Dear R users,
>
> I would like to calculate a cumulative sum as following: on the i-th row, in the
> j-th column of a matrix, I would like to obtain the sum of the (i-1) preceding elements of
> this j-th column.
> Could I avoid a "for" loop?
>
> Thank you,
> Tristan Lorino
>
> ----------------------
> École Nationale Vétérinaire d'Alfort - http://www.vet-alfort.fr,
> Tél. 01 43 96 70 33
> Mél. tlorino at vet-alfort.fr
> Site personnel : http://daedale.free.fr
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list