To make it simple, i would like a column C to be equal to the Lag of a column B, with the shift argument depending on the integers in the column A, so I want:
A | B | C
0 | 5 | 5
2 | 6 | NA
3 | 7 | NA
2 | 8 | 6
I tried:
library(dplyr)
library(Hmisc)
data <- mutate(data,
C= Lag(B, shift=as.integer(A)),
but it doesn't work, i get NAs only, it's probably a type issue but i'm not sure as even with the as.integer it doesn't work, Does someone have any idea why it doesn't work?
Thanks a lot