# Create fake data frame
A <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)
B <- c(1:10)
Data <- data.frame(A, B)
# Find percentage change from two periods before
Out <- PercChange(Data, Var = 'B',
type = 'proportion',
NewVar = 'PercentChange',
slideBy = -2)
Out
Run the code above in your browser using DataLab