2019年12月17日火曜日

EPS 2019DEC17



> eps_year_xts["2019::"]
             [,1]
2019-01-01 134.39
2019-04-01 135.27
2019-07-01 133.95
2019-10-01 142.58
2020-01-01 146.27
2020-04-01 152.08
2020-07-01 159.78
2020-10-01 165.15

$tac eps.txt 
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75 $154.54 $135.27
9/30/2019 (Prlim.) 2976.74 $39.82 $33.99 20.71 23.84 $152.98 $132.90
12/31/2019 $40.42 $36.51 20.01 22.56 $158.37 $140.45
3/31/2020 $40.60 $36.97 19.68 22.25 $160.98 $142.40
6/30/2020 $43.65 $39.88 19.26 21.50 $164.49 $147.35
9/30/2020 $45.92 $42.64 18.57 20.31 $170.59 $156.01
12/31/2020 $46.35 $42.37 17.95 19.58 $176.52 $161.87

When entries started with "6/30/2019", I have to put NR+1 in order to adjust sequence number.

$tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR+1"] <- "$NF}'
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 140.45
eps_year_xts["2019::"][5] <- 142.40
eps_year_xts["2019::"][6] <- 147.35
eps_year_xts["2019::"][7] <- 156.01
eps_year_xts["2019::"][8] <- 161.87

2019年12月5日木曜日

xts , matrix and data frame index and dimensions.


# the sample of xts object.

> cli_xts["2019::"]
               oecd      usa    china     ea19
2019-01-01 99.53469 99.71027 98.70411 99.77903
2019-02-01 99.43623 99.54673 98.69403 99.66678
2019-03-01 99.36298 99.40987 98.71894 99.55812
2019-04-01 99.30513 99.28092 98.75597 99.45299
2019-05-01 99.25108 99.15568 98.80080 99.34872
2019-06-01 99.20237 99.03459 98.86234 99.24314
2019-07-01 99.15969 98.91864 98.94160 99.14515
2019-08-01 99.12648 98.81747 99.02364 99.06464
2019-09-01 99.10692 98.75613 99.10512 99.00034

# in order to create the sample matirx, use matrix() to transform xts to marix

> matrix(cli_xts["2019::"],ncol=4)
          [,1]     [,2]     [,3]     [,4]
 [1,] 99.53469 99.71027 98.70411 99.77903
 [2,] 99.43623 99.54673 98.69403 99.66678
 [3,] 99.36298 99.40987 98.71894 99.55812
 [4,] 99.30513 99.28092 98.75597 99.45299
 [5,] 99.25108 99.15568 98.80080 99.34872
 [6,] 99.20237 99.03459 98.86234 99.24314
 [7,] 99.15969 98.91864 98.94160 99.14515
 [8,] 99.12648 98.81747 99.02364 99.06464
 [9,] 99.10692 98.75613 99.10512 99.00034

# matrix require 2 dim. index like [1,] to pick up the designated row.

> matrix(cli_xts["2019::"],ncol=4)[1,]
[1] 99.53469 99.71027 98.70411 99.77903

# while xts requires [1].

> cli_xts["2019::"][1]
               oecd      usa    china     ea19
2019-01-01 99.53469 99.71027 98.70411 99.77903

> cli_xts["2019::"][1,1]
               oecd
2019-01-01 99.53469

> matrix(cli_xts["2019::"],ncol=4)[1,1]
[1] 99.53469

# for the case of data frame.

> data.frame(cli_xts["2019::"],ncol=4)
               oecd      usa    china     ea19 ncol
2019-01-01 99.53469 99.71027 98.70411 99.77903    4
2019-02-01 99.43623 99.54673 98.69403 99.66678    4
2019-03-01 99.36298 99.40987 98.71894 99.55812    4
2019-04-01 99.30513 99.28092 98.75597 99.45299    4
2019-05-01 99.25108 99.15568 98.80080 99.34872    4
2019-06-01 99.20237 99.03459 98.86234 99.24314    4
2019-07-01 99.15969 98.91864 98.94160 99.14515    4
2019-08-01 99.12648 98.81747 99.02364 99.06464    4
2019-09-01 99.10692 98.75613 99.10512 99.00034    4

# a index works in the same way as matrix.

> data.frame(cli_xts["2019::"],ncol=4)[1,]
               oecd      usa    china     ea19 ncol
2019-01-01 99.53469 99.71027 98.70411 99.77903    4


> data.frame(cli_xts["2019::"],ncol=4)[1,1]
[1] 99.53469

# a single dimention index also works fine for data frame
# but it takes column for the parameter

> data.frame(cli_xts["2019::"],ncol=4)[1]
               oecd
2019-01-01 99.53469
2019-02-01 99.43623
2019-03-01 99.36298
2019-04-01 99.30513
2019-05-01 99.25108
2019-06-01 99.20237
2019-07-01 99.15969
2019-08-01 99.12648
2019-09-01 99.10692

# on the other hand, single dim. index taken for the row.

> cli_xts["2019::"][1]
               oecd      usa    china     ea19
2019-01-01 99.53469 99.71027 98.70411 99.77903