[R] Relative subscripts?

Mark Na mtb954 at gmail.com
Wed May 6 01:00:29 CEST 2009

Dear R-helpers,

I have a dataframe with several columns, one of which is called LENGTH.

I would like to make a new column called DIFF containing the value of
LENGTH minus LENGTH in the previous row, like this:

1  1     10   NA
2  2     15    5
3  3     20    5
4  4     12   -8
5  5     18    6

I'd like to think there are "relative subscripts" in R but I can't
find any reference to such a thing.

Any help solving this problem would be much appreciated, thanks!

Mark Na

More information about the R-help mailing list