Thanks all for the help, that is done.
Gabor Grothendieck wrote: > > Here are a couple of ways: > >> tail(a, -2) - head(a, -2) > [1] 2 5 -3 >> c(ts(a) - lag(ts(a), -2)) > [1] 2 5 -3 > > > On Mon, Aug 11, 2008 at 11:26 AM, dott <[EMAIL PROTECTED]> wrote: >> >> Hi, >> >> I'd like to take difference for a sequence a between a_i and a_i-2, for >> instance, >> a<-c(2,3,4,8,1) >> I need (2, 5, -3) as a result. If not using a for loop, can anyone help >> me? >> Thanks a lot. >> >> Dot >> -- >> View this message in context: >> http://www.nabble.com/R-help--how-to-take-difference-in-next-two-elements-tp18927968p18927968.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> 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. > > -- View this message in context: http://www.nabble.com/R-help--how-to-take-difference-in-next-two-elements-tp18927968p18930532.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.