[R] how to get growth rate of a (time series) data?
R. Michael Weylandt
michael.weylandt at gmail.com
Wed Jun 19 13:24:01 CEST 2013
On Wed, Jun 19, 2013 at 12:04 PM, Yanyuan Zhu <yyz at tongji.edu.cn> wrote:
> Hello all, now I'm trying to switch from Excel to R to deal with the data,
> and as a newbie i got the problem as follows.
> suppose I have a data named "test"
> test<- data.frame(year=c(1996:2011),
> in which Y means the GDP of a country
> If i want to get Delta Y = Y(t)-Y(t-1) , i could use diff() in R
> but what if i want to get gY=(Y(t)-Y(t-1))/Y(t-1)?
> seems diff(test$Y)/(test$Y)[-1] doesnt work ...
Odd, I would have thought it did.
No matter anyways: if you are using time series data, I'd strongly
recommend that you place your data in an object of the "xts" class and
use all of the time series functionality available for those objects.
Notably, you'll also want to load the "TTR" package (all of these are
available through the install.packages() function off the CRAN mirror
system) and to use its ROC function.
> thanks in advance
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help