Re: [R] iterated sum

2013-12-14 Thread arun
Hi, Try:  x[-1]+x[-length(x)] A.K. On Saturday, December 14, 2013 5:46 AM, 水静流深 <1248283...@qq.com> wrote: x<-c(1,4,9,20,3,7) i want to get a serie c(5,13,29,23,10). y <- c() for (i in 2:length(x)){     y[i-1] <- x[i-1]+x[i]} is there more simple way to get?     [[alternative HTML version del

Re: [R] iterated sum

2013-12-14 Thread Ted Harding
On 14-Dec-2013 10:46:10 Ë®¾²Á÷Éî wrote: > x<-c(1,4,9,20,3,7) > i want to get a serie c(5,13,29,23,10). > y <- c() > for (i in 2:length(x)){ > y[i-1] <- x[i-1]+x[i]} > > is there more simple way to get? x <- c(1,4,9,20,3,7) N <- length(x) x[1:(N-1)] + x[2:N] # [1] 5 13 29 23 10 B

[R] iterated sum

2013-12-14 Thread ????????
x<-c(1,4,9,20,3,7) i want to get a serie c(5,13,29,23,10). y <- c() for (i in 2:length(x)){ y[i-1] <- x[i-1]+x[i]} is there more simple way to get? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.eth