XTS数据占用太多内存空间?

问题描述 投票:1回答:1

我以下列方式使用来自quantmod的GetSymbols:

temp0 <- getSymbols("AAPL",src = 'yahoo',from=Sys.Date()-100000,to = Sys.Date(),auto.assign=FALSE);

而且我用很少的空间得到了大的xts对象。

temp0   Large xts (59664 elements, 546.2 Kb)

但是,有时xts对象占用太多空间。这是我的一些对象。

temp1   Large xts (34848 elemnts, 25.5 Mb)
t12     Large xts (36 elements, 25.2 Mb)

t12是head(temp1)的结果,这里是t12:

structure(t12)
                    Bid.Price Bid.Size Ask.Price Ask.Size Trade.Price Volume
2019-05-29 17:00:01  116.4922       51  116.5000      143    116.4922    208
2019-05-29 17:00:02  116.4922       71  116.5000      142    116.5000      2
2019-05-29 17:00:04  116.4844      427  116.4922       92    116.4844     72
2019-05-29 17:00:08  116.4922       83  116.5000      156    116.4922     21
2019-05-29 17:01:01  116.4922       71  116.5000      128    116.4922     34
2019-05-29 17:01:08  116.5000       13  116.5078      228    116.4922    192

我确实发现,如果我使用attribute(t12),我会发现#na.action以及attr(,“ index”)包含许多值,超过200万。

temp1是非常大的数据集,我从中过滤了大部分数据,但是似乎该对象将旧的无用数据保留在#na.actionattr(,“ index”)] >>中,如果没有更多的话。

我不知道为什么会这样,但是我该如何清理呢?如何使我的6行t12达到适当的最小尺寸?

如果有帮助,请输出max.print = 10的完整属性:

> attributes(t12)
$class
[1] "xts" "zoo"

$.indexCLASS
[1] "POSIXct" "POSIXt" 

$tclass
[1] "POSIXct" "POSIXt" 

$na.action
 [1]  1  3  6  7  8 12 13 15 16 17
 [ reached getOption("max.print") -- omitted 2201657 entries ]
attr(,"class")
[1] "omit"
attr(,"index")
 [1] 1519772400 1519772402 1519772407 1519772409 1519772410 1519772420 1519772424 1519772428 1519772429 1519772430
 [ reached getOption("max.print") -- omitted 2201657 entries ]

$index
[1] 1559167201 1559167202 1559167204 1559167208 1559167261 1559167268
attr(,"tzone")
[1] "America/Chicago"
attr(,"tclass")
[1] "POSIXct" "POSIXt" 

$dim
[1] 6 6

$dimnames
$dimnames[[1]]
NULL

$dimnames[[2]]
[1] "Bid.Price"   "Bid.Size"    "Ask.Price"   "Ask.Size"    "Trade.Price" "Volume"

如何从xts中删除多余的信息?

UPDATE

根据上面的代码,我似乎已经找到解决该问题的方法。

t12 <- rbind(t12[1,],t12)
t12[1,1] < NA
t12 <- na.omit(t12)

我将数据的第一行添加到顶部,并将第一个条目设置为NA。然后,当我对数据集进行na.omit时,其余数据与最初的t12相同,但是干净,没有多余的不良数据。

问题是我已经使用na.omit()创建temp1集,但不知道为什么有时na.omit()无法正确清除数据?可能具有非常大的数据集?

我正在以下列方式使用来自quantmod的GetSymbols:temp0

r xts zoo quantmod
1个回答
0
投票

根据上面的代码,我似乎已经找到解决该问题的方法。

© www.soinside.com 2019 - 2024. All rights reserved.