> prices <- c(1.71, 1.90, 1.68, 1.46, 1.86, 1.85, 1.88, 1.86, 1.62, 1.45, 0.67, 1.18, 1.68, 1.74, 1.70, 1.49, 1.81, 1.96, 1.97, 1.91, 1.89, 1.65, 0.70, 1.17, 1.76, 1.78, 1.53, 1.90) > turkey.ts <- ts(prices, start=c(2006, 1), end=c(2008, 4), frequency=12) > turkey.ts Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2006 1.71 1.90 1.68 1.46 1.86 1.85 1.88 1.86 1.62 1.45 0.67 1.18 2007 1.68 1.74 1.70 1.49 1.81 1.96 1.97 1.91 1.89 1.65 0.70 1.17 2008 1.76 1.78 1.53 1.90
> attributes(turkey.ts) $tsp [1] 2006.00 2008.25 12.00 $class [1] "ts"
> start(turkey.ts) [1] 2006 1 > end(turkey.ts) [1] 2008 4 > frequency(turkey.ts) [1] 12 > deltat(turkey.ts) [1] 0.08333333
> # Create a new ts object that lags > # the original by two time periods. > lag(turkey.ts, 2) Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2005 1.71 1.90 2006 1.68 1.46 1.86 1.85 1.88 1.86 1.62 1.45 0.67 1.18 1.68 1.74 2007 1.70 1.49 1.81 1.96 1.97 1.91 1.89 1.65 0.70 1.17 1.76 1.78 2008 1.53 1.90 > # Compute differences of successive observations. > diff(turkey.ts) Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2006 0.19 -0.22 -0.22 0.40 -0.01 0.03 -0.02 -0.24 -0.17 -0.78 0.51 2007 0.50 0.06 -0.04 -0.21 0.32 0.15 0.01 -0.06 -0.02 -0.24 -0.95 0.47 2008 0.59 0.02 -0.25 0.37