这是我的代码,我遍历DD xts
的列
我将3个最大值存储在outl
问题是,当我找到outl
时,我有第一列的正确日期,但其他人没有。有没有办法纠正?
Outpout = NULL
i = 1
while (i<dim(DD)[2]+1){
outl = sort(DD[,i], TRUE)[1:3]
i = i+1
Outpout = cbind(Outpout,outl)
}
以下是我的Outpout
outl outl outl outl outl outl outl outl outl
2015-08-12 17:00:00 382.0823 308.5812 382.7290 305.5518 306.5123 364.4946 359.3629 361.8381 358.2999
2014-06-30 17:00:00 363.0952 243.4499 307.9904 305.4652 177.9962 361.2023 348.1868 358.5445 350.9746
2016-06-30 17:00:00 327.6692 160.4543 193.0451 141.0073 128.6539 346.6693 328.9490 331.9964 327.2888
也许有一种更好的方法可以找到每列最多3个,并且日期为
我的样本
a b
2011-01-03 12:00:00 2.838006e-01 1.094922e+00
2011-01-03 17:00:00 6.655318e-01 2.572599e+01
2011-01-03 18:00:00 1.364121e-01 5.365103e-01
2011-01-03 19:00:00 1.805002e+01 1.847452e-01
2011-01-04 04:00:00 2.765880e-01 8.721402e-02
2011-01-04 05:00:00 3.213491e-02 2.124598e-01
2011-01-04 10:00:00 1.482882e+00 2.184471e+00