[R] apply calculations to elements in a vector
Berend Hasselman
bhh at xs4all.nl
Fri Nov 16 16:13:22 CET 2012
On 16-11-2012, at 15:50, 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.?
Another way of doing this
rowSums(embed(a,2))
Berend
More information about the R-help
mailing list