Re: [R] inverse cumsum

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Wed, 18 Jun 2008 12:37:12 +0200

Alfredo Alessandrini wrote:
> I've a matrix like this:
>
> 1985 1.38 1.27 1.84 2.10 0.59 3.47
> 1986 1.05 1.13 1.21 1.54 0.21 2.14
> 1987 1.33 1.21 1.77 1.44 0.27 2.85
> 1988 1.86 1.06 2.33 2.14 0.55 1.40
> 1989 2.10 0.65 2.74 2.43 1.19 1.45
> 1990 1.55 0.00 1.59 1.94 0.99 2.14
> 1991 0.92 0.72 0.50 1.29 0.54 1.22
> 1992 2.15 1.28 1.23 2.26 1.22 3.17
> 1993 1.50 0.87 1.68 1.97 0.83 2.55
> 1994 0.69 0.00 0.76 1.89 0.60 0.87
> 1995 1.13 1.04 1.19 1.52 1.13 1.78
>
> Can I utilise a cumsum inverse? from 1995 to 1985?
>
i guess you mean columnwise cumsums computed starting from the bottom up? then this should do (given that your data is in matrix m, and years are row labels, not data):

rc = nrow(m)
cumsums = apply(m[rc:1,], 2, cumsum)[rc:1,]

vQ



R-help_at_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. Received on Wed 18 Jun 2008 - 11:13:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 18 Jun 2008 - 19:30:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive