Try this: x <- c(10, 20, 30) head(x, -1) + tail(x, -1)
I hope it helps. Best, Dimitris On 11/16/2012 3:50 PM, e-letter wrote: > Readers, > > If a vector consists of: > > 10 > 20 > 30 > > how to create a new vector based upon the results of calculations to > the elements, e.g. addition of successive elements, so that a new > vector would be: > > 30 > 50 > > i.e. 10+20, then 20+30, etc.? > > ______________________________________________ > 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. > -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ ______________________________________________ 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.