2

I want to create a leading variable in R where given old variable x, new variable y is such that y[t] = x[t+1]
e.g. as in Lagging Variables in R

embed() the solution in above doesn't let you use dimension < 1. Is there an alternative built-in function that will help here?

Community
  • 1
  • 1
wgyn888
  • 21
  • 1

1 Answers1

6

If x is your original variable, then y <- c(x[-1], NA) is a leading version.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187