An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131214/f3d672a1/attachment.pl>
iterated sum
3 messages · 水静流深, (Ted Harding), arun
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 Best wishes, Ted. ------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at wlandres.net> Date: 14-Dec-2013 Time: 10:54:00 This message was sent by XFMail
Hi, Try: ?x[-1]+x[-length(x)] A.K.
On Saturday, December 14, 2013 5:46 AM, ???? <1248283536 at 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 deleted]]
______________________________________________
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.