Skip to content
Prev 244059 / 398506 Next

How can I refer to actual (n) and previous (n-1) elements in a vector?

Hi Marianne,

You have to be very careful with subsetting when doing something like that -
that's where you went wrong with your original construct. This version works:
[1]  9 14  9  2  4 12 14 11  9


But here's a more elegant way:
[1]  9 14  9  2  4 12 14 11  9

and I'm sure there are even nicer solutions.

Sarah

On Mon, Dec 6, 2010 at 12:13 PM, Marianne Stephan
<mariannestephan at hotmail.com> wrote: