On 06-04-2012, at 10:27, jpm miao wrote: > Hello, > > Is there a function in R that calculates the year-on-year growth rate of > some time series? > > In EView the function is @pchy.
This might do what you need pchy <- function(x) { if(!is.ts(x)) stop("x is not a timeseries") x.freq <- tsp(x)[3] if(!(x.freq %in% c(1,2,4,12))) stop("Invalid frequency of timeseries x (must be 1, 2, 4, 12)") y <- diff(x,lag=x.freq)/lag(x,-x.freq) return(y) } Berend ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.