2020年9月1日火曜日

行列の計算 matrix()

 

> 1:15
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

> matrix(1:15,ncol=3)
     [,1] [,2] [,3]
[1,]    1    6   11
[2,]    2    7   12
[3,]    3    8   13
[4,]    4    9   14
[5,]    5   10   15

> diff(matrix(1:15,ncol=3))
     [,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
[3,]    1    1    1
[4,]    1    1    1


> c(1:7,NA,9:15)
 [1]  1  2  3  4  5  6  7 NA  9 10 11 12 13 14 15
> w <- matrix(c(1:7,NA,9:15), ncol=5)
> w
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5   NA   11   14
[3,]    3    6    9   12   15

> v <- as.vector(w)
> v[is.na(v)]
[1] NA
> v[is.na(v)] <- 8
> matrix(v,ncol=dim(w)[2])
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5    8   11   14
[3,]    3    6    9   12   15
> w <- matrix(v,ncol=dim(w)[2])
> w
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    4    7   10   13
[2,]    2    5    8   11   14
[3,]    3    6    9   12   15

EPS 2020SEP01

 


> eps_year_xts["2020::"]
             [,1]
2020-01-01 116.33
2020-04-01 100.29
2020-07-01  94.83
2020-10-01  92.54
2021-01-01 112.31
2021-04-01 128.51
2021-07-01 138.90
2021-10-01 146.96


$  tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'
eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.16
eps_year_xts["2019::"][7] <- 93.44
eps_year_xts["2019::"][8] <- 89.68
eps_year_xts["2019::"][9] <- 110.65
eps_year_xts["2019::"][10] <- 129.66
eps_year_xts["2019::"][11] <- 139.84
eps_year_xts["2019::"][12] <- 148.29