Let's say the original data set has 100 observations
X1, X2, X3, --- , X100
Now I want to rearrange the data as follows and create a new data set
Current_State Lag1 Lag2 Lag3 Lag4 Lag5
X100 X99 X98 X97 X96 X95
X99 X98 X97 X96 X95 X94
X98 X97 X96 X95 X94 X93
X97 X96 X95 X94 X93 X92
. . .
X6 X5 X4 X3 X2 X1
Is there anyway to do this simple manipulation in r or matlab rather than doing a series of for loops.