pct_change {metools} | R Documentation |
pct_change calculate the percentual change in t periods of a serie. We can use this function to calculate the acumulated variation of an index, for example to calculate the accumulated variation in 12 months just set t parameter to 12
pct_change(data, colnum, t = nrow(data[colnum]) - 1, nafill = NA)
data |
a dataframe |
colnum |
number of column |
t |
number of periods to accumulate (default= number of rows) |
nafill |
set value to fill NA's before first t value |
Return a dataframe.
v=data.frame(test=c(1,2,3,4,5,6,7,8,9,10,11,12,13))
pct_change(v)