如下所示,建立表t:
sym = `600001`600002`600002`600002`600003`600003`600001`600001`600001
price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29
qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800
timestamp = [09:34:07,09:35:42,09:36:51,09:36:59,09:35:47,09:36:26,09:34:16,09:35:26,09:36:12]
t = table(timestamp, sym, qty, price);
t的数据如下:
timestamp sym qty price
09:34:07 600001 2,200 49.6
09:35:42 600002 1,900 29.46
09:36:51 600002 2,100 29.52
09:36:59 600002 3,200 30.02
09:35:47 600003 6,800 174.97
09:36:26 600003 5,400 175.23
09:34:16 600001 1,300 50.76
09:35:26 600001 2,500 50.32
09:36:12 600001 8,800 51.29
pivot by 后生成表t1:
t1 = select price from t pivot by timestamp, sym;
t1的数据如下:
timestamp 600001 600002 600003
09:34:07 49.6
09:34:16 50.76
09:35:26 50.32
09:35:42 29.46
09:35:47 174.97
09:36:12 51.29
09:36:26 175.23
09:36:51 29.52
09:36:59 30.02
把t1变成矩阵m,label是t1的timestamp列:
m = matrix(t1[,1:]).rename!(t1.timestamp,t1.colNames()[1:])
m的数据:
label 600001 600002 600003
09:34:07 49.6
09:34:16 50.76
09:35:26 50.32
09:35:42 29.46
09:35:47 174.97
09:36:12 51.29
09:36:26 175.23
09:36:51 29.52
09:36:59 30.02
现在我想把矩阵m再转换成表,要求表结构与t1相同,我用table(m)转换时少了矩阵的lable列,即timestamp没有了,请问有什么简单的转换办法保证label列不丢?