2013年2月3日日曜日

Rのtsオブジェクト

https://sites.google.com/site/leihcrev/r/timeseries

ts(mts)は基本的に各列にそれぞれの名前がついている行列のデータ。

例:

> library(datasets)
> EuStockMarkets
Time Series:
Start = c(1991, 130)
End = c(1998, 169)
Frequency = 260
             DAX    SMI    CAC   FTSE
1991.496 1628.75 1678.1 1772.8 2443.6
1991.500 1613.63 1688.5 1750.5 2460.2
1991.504 1606.51 1678.6 1718.0 2448.2
1991.508 1621.04 1684.1 1708.1 2470.4
1991.512 1618.16 1686.6 1723.1 2484.7
1991.515 1610.61 1671.6 1714.3 2466.8
1991.519 1630.75 1682.9 1734.5 2487.9
1991.523 1640.17 1703.6 1757.4 2508.4
1991.527 1635.47 1697.5 1754.0 2510.5
1991.531 1645.89 1716.3 1754.3 2497.4
1991.535 1647.84 1723.8 1759.8 2532.5
1991.538 1638.35 1730.5 1755.5 2556.8
 ...

 > str(EuStockMarkets)
 mts [1:1860, 1:4] 1629 1614 1607 1621 1618 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "DAX" "SMI" "CAC" "FTSE"
 - attr(*, "tsp")= num [1:3] 1991 1999 260
 - attr(*, "class")= chr [1:2] "mts" "ts"

> EuStockMarkets[3,1]
    DAX
1606.51

> EuStockMarkets[,"DAX"]
Time Series:
Start = c(1991, 130)
End = c(1998, 169)
Frequency = 260
   [1] 1628.75 1613.63 1606.51 1621.04 1618.16 1610.61 1630.75 1640.17
   [9] 1635.47 1645.89 1647.84 1638.35 1629.93 1621.49 1624.74 1627.63
  [17] 1631.99 1621.18 1613.42 1604.95 1605.75 1616.67 1619.29 1620.49
  [25] 1619.67 1623.07 1613.98 1631.87 1630.37 1633.47 1626.55 1650.43
  [33] 1650.06 1654.11 1653.60 1501.82 1524.28 1603.65 1622.49 1636.68
  [41] 1652.10 1645.81 1650.36 1651.55 1649.88 1653.52 1657.51 1649.55
...

0 件のコメント:

コメントを投稿