Examples for 'stats::ts'


Time-Series Objects

Aliases: ts as.ts as.ts.default is.ts Ops.ts cbind.ts is.mts [.ts t.ts

Keywords: ts

### ** Examples

require(graphics)

ts(1:10, frequency = 4, start = c(1959, 2)) # 2nd Quarter of 1959
     Qtr1 Qtr2 Qtr3 Qtr4
1959         1    2    3
1960    4    5    6    7
1961    8    9   10     
print( ts(1:10, frequency = 7, start = c(12, 2)), calendar = TRUE)
   p1 p2 p3 p4 p5 p6 p7
12     1  2  3  4  5  6
13  7  8  9 10         
# print.ts(.)
## Using July 1954 as start date:
gnp <- ts(cumsum(1 + round(rnorm(100), 2)),
          start = c(1954, 7), frequency = 12)
plot(gnp) # using 'plot.ts' for time-series plot
plot of chunk example-stats-ts-1
## Multivariate
z <- ts(matrix(rnorm(300), 100, 3), start = c(1961, 1), frequency = 12)
class(z)
[1] "mts"    "ts"     "matrix"
head(z) # as "matrix"
       Series 1   Series 2     Series 3
[1,]  0.3299870  2.8962729 -0.077289132
[2,] -0.3227181 -0.1459187 -0.367801898
[3,]  1.0132104  0.6676625 -0.008443041
[4,]  1.3588910 -0.3344092 -0.379653435
[5,] -0.8863595  0.6112516 -0.083050450
[6,] -1.0831261 -0.2879630  1.774093002
plot(z)
plot of chunk example-stats-ts-1
plot(z, plot.type = "single", lty = 1:3)
plot of chunk example-stats-ts-1
## A phase plot:
plot(nhtemp, lag(nhtemp, 1), cex = .8, col = "blue",
     main = "Lag plot of New Haven temperatures")
plot of chunk example-stats-ts-1

[Package stats version 4.2.3 Index]