- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很高兴使用这段代码运行:
z=lapply(filename_list, function(fname){
read.zoo(file=fname,header=TRUE,sep = ",",tz = "")
})
xts( do.call(rbind,z) )
直到脏数据出现在一个文件的末尾:
Open High Low Close Volume
2011-09-20 21:00:00 1.370105 1.370105 1.370105 1.370105 1
这位于下一个文件的开头:
Open High Low Close Volume
2011-09-20 21:00:00 1.370105 1.371045 1.369685 1.3702 2230
所以rbind.zoo
提示重复。
我无法使用 something like :
y <- x[ ! duplicated( index(x) ), ]
因为它们位于列表内的不同动物园对象中。我不能使用aggregate
,如 suggested here因为它们是动物园对象的列表,而不是一个大的动物园对象。由于重复项,我无法获得一个大对象。第 22 条军规。
因此,当事情变得困难时,困难的黑客将一些 for 循环组合在一起(请原谅打印和停止,因为这还不是工作代码):
indexes <- do.call("c", unname(lapply(z, index)))
dups=duplicated(indexes)
if(any(dups)){
duplicate_timestamps=indexes[dups]
for(tix in 1:length(duplicate_timestamps)){
t=duplicate_timestamps[tix]
print("We have a duplicate:");print(t)
for(zix in 1:length(z)){
if(t %in% index(z[[zix]])){
print(z[[zix]][t])
if(z[[zix]][t]$Volume==1){
print("-->Deleting this one");
z[[zix]][t]=NULL #<-- PROBLEM
}
}
}
}
stop("There are duplicate bars!!")
}
我遇到的问题是将 NULL 分配给动物园行并不会删除它(NextMethod("[<-") 中的错误:替换长度为零)。好的,所以我做了一个过滤器复制,没有违规的项目......但我被这些绊倒了:
> z[[zix]][!t,]
Error in Ops.POSIXt(t) : unary '!' not defined for "POSIXt" objects
> z[[zix]][-t,]
Error in `-.POSIXt`(t) : unary '-' is not defined for "POSIXt" objects
附注虽然对于“在动物园对象列表中重复行”这一实际问题的高级解决方案非常受欢迎,但这里的问题具体是关于如何在给定 POSIXt 索引对象的情况下从动物园对象中删除行。
<小时/>一点测试数据:
list(structure(c(1.36864, 1.367045, 1.370105, 1.36928, 1.37039,
1.370105, 1.36604, 1.36676, 1.370105, 1.367065, 1.37009, 1.370105,
5498, 3244, 1), .Dim = c(3L, 5L), .Dimnames = list(NULL, c("Open",
"High", "Low", "Close", "Volume")), index = structure(c(1316512800,
1316516400, 1316520000), class = c("POSIXct", "POSIXt"), tzone = ""), class = "zoo"),
structure(c(1.370105, 1.370115, 1.36913, 1.371045, 1.37023,
1.37075, 1.369685, 1.36847, 1.367885, 1.3702, 1.36917, 1.37061,
2230, 2909, 2782), .Dim = c(3L, 5L), .Dimnames = list(NULL,
c("Open", "High", "Low", "Close", "Volume")), index = structure(c(1316520000,
1316523600, 1316527200), class = c("POSIXct", "POSIXt"), tzone = ""), class = "zoo"))
<小时/>
更新:感谢G. Grothendieck对于行删除解决方案。在实际代码中我遵循了Joshua的建议和 GSee获取 xts 对象列表而不是 Zoo 对象列表。所以我的代码变成了:
z=lapply(filename_list, function(fname){
xts(read.zoo(file=fname,header=TRUE,sep = ",",tz = ""))
})
x=do.call.rbind(z)
(顺便说一句,请注意对 do.call.rbind
的调用。这是因为 rbind.xts
存在一些严重的内存问题。请参阅 https://stackoverflow.com/a/12029366/841830 )
然后我删除重复项作为后处理步骤:
dups=duplicated(index(x))
if(any(dups)){
duplicate_timestamps=index(x)[dups]
to_delete=x[ (index(x) %in% duplicate_timestamps) & x$Volume<=1]
if(nrow(to_delete)>0){
#Next line says all lines that are not in the duplicate_timestamp group
# OR are in the duplicate timestamps, but have a volume greater than 1.
print("Will delete the volume=1 entry")
x=x[ !(index(x) %in% duplicate_timestamps) | x$Volume>1]
}else{
stop("Duplicate timestamps, and we cannot easily remove them just based on low volume.")
}
}
最佳答案
如果 z1
和 z2
是您的动物园对象,则进行 rbind
同时删除 z2
中的任何重复项:
rbind( z1, z2[ ! time(z2) %in% time(z1) ] )
关于删除动物园对象中具有指定时间的点,上面已经说明了这一点,但一般来说,如果tt
是要删除的时间向量:
z[ ! time(z) %in% tt ]
或者如果我们知道 tt
中有一个元素,则 z[ time(z) != tt ]
。
关于r - 如何在给定时间戳的情况下从 Zoo/xts 对象中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11944626/
我一直在使用 apache Zookeeper,并被要求阅读包含以下属性的 Zoo.cfg: tickTime=2000 dataDir=/var/lib/zookeeper clientPort=2
我一直需要获取交易数据并按天、周、月、季度、年进行汇总——本质上,它是时间序列数据。我开始申请zoo/xts到我的数据,希望我可以更快地聚合数据,但我要么不完全理解包的目的,要么我试图不正确地应用它。
我有一个按时索引的动物园数据集。有些行有相同的数据,所以我基本上只想删除这些重复的行。 redpardiff relpar 2012-07-
本文整理了Java中org.deeplearning4j.zoo.ZooModel类的一些代码示例,展示了ZooModel类的具体用法。这些代码示例主要来源于Github/Stackoverflow/
我想使用动物园函数 rollapply 在时间序列上应用函数(例如平均值),但只使用最后 N 个已知点。例如: x = zoo(c(1,2,3,4), order.by=c(10,11,12,13))
我找遍了所有地方,但我找不到以前问过这个问题的地方。 将这些数据放入适当的动物园系列的干净方法是什么?这个版本是复制/粘贴,使这篇文章更容易,但它总是以下表的形式出现(来自文本文件)。我的 read.
我有一个动物园时间序列: z str(z) ‘zoo’ series from (03/27/10 21:00:00) to (03/28/10 07:00:00) Data: num [1:1
在R中,如何为新类实现运算符重载(如+,-,*,./)?我在ops.R中检查了动物园图书馆的源代码。以下代码能完成这项工作吗? Ops.zoo `+.mychar` x y class(x)
我和我的同事有两个数据集,每个数据集每天有 1 个观察值,但是天数在每个数据集中不连续,并且在两个数据集之间不一致。 我们将每个转换为一个动物园对象并合并,从时间索引中删除那些日子在第二个数据集中有观
数据看起来像 Time Set1 Set2 10:19:38.551629 16234 16236 10:19:41.408010 16234 16236
我很困惑为什么不能 Select x.continent, x.name From world x Where x.name <= ALL (select y.name from world y wh
我正在使用 joomla 3,zoo 组件。 在系统后端,我有以下代码来显示安装的每个动物园应用程序中的项目数量: getItemCount(); ?> 我需要编辑此代码以仅显示“已发布”的项目数量。
我在 joomla component zoo 工作。我需要的是在项目布局中呈现这个项目 ID。 我可以获取所有动物园项目 ID 的列表,但无法找到如何获取 $this('id') 我不能使用菜单 I
我试图了解我过去在输入动物园对象时遇到的困难。尽管 tz 的默认参数应该是 "",但 read.zoo 的以下两种用法给出了不同的结果,这是两个 read.zoo 调用之间的唯一区别: Lines
我有看起来像这样的数据: > head(data) groupname ob_time dist.mean dist.sd dur.mean dur.sd c
我有多个时间序列数据图,我需要在每个图中有一条水平线,但具有不同的水平值(例如,第一个图:h=50,第二个图:h=48 ...)。 我试过 abline(h=50...我在每个图中都得到了水平线。 我
我有一个 yearmon 对象: require(zoo) date1 format(date1, "%b") ## Month, char, abbreviated [1] "Mar" > for
我很高兴使用这段代码运行: z=lapply(filename_list, function(fname){ read.zoo(file=fname,header=TRUE,sep = ","
我正在使用 R 中的 zoo 包来分析时间序列数据。我有以下数据文件: Date(dd-mm-yy),Time(hh:mm:ss),Julian_Day,AOT_1640,AOT_1020,AOT_8
TF Objection Detection Zoo 中的模型有 meta+ckpt 文件、Frozen.pb 文件和 Saved_model 文件。 我尝试使用 meta+ckpt 文件进一步训练,
我是一名优秀的程序员,十分优秀!