On 12 Mar 2009, at 13:22, richard.cot...@hsl.gov.uk wrote:

I'm trying to write a loop to sum my data in the following way:
(the second - the first) + (the third - the second) + (the fourth -
the third) + ...
for each column.

This is just sum(diff(x)), or even x[length(x)] - x[1].


I think rowSums gives what's intended,

rowSums(diff( matrix(c(1,2,3,4,5,6),ncol=2) ))

(but i'd give heads or tails as to whether this was an oversimplification of the real problem )


baptiste


_________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to