Padding: leading & lagged variables in R data frames
Oftentimes, it happens I need to calculate the difference of something between two periods. If each row represents a period, the fastest thing to do is to lag the variable you need to perform calculations on. In R, the lag() function from the stats package is an option, but you’ll…