timeBasedSeq 函数重复它创建的一些日子! [英] timeBasedSeq function repeats some of the days it creates!

查看:29
本文介绍了timeBasedSeq 函数重复它创建的一些日子!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xts 包中的 timeBasedSeq 函数作为时间序列/动物园对象中的索引,但它重复了它创建的某些日子!这会导致动物园出现问题,因为‘order.by’中的索引条目不是唯一的".

I am using The timeBasedSeq function from xts package to use as index in a time series/zoo object but it repeats some of the days it creates! Which than causes problems with zoo because the "index entries in ‘order.by’ are not unique".

例如:

timeBasedSeq("19860601/19861231")

timeBasedSeq("19860601/19861231")

将创建

..."1986-10-23" "1986-10-24" "1986-10-25" "1986-10-26" "1986-10-26" "1986-10-27" "1986-10-28" "1986-10-29""...

..."1986-10-23" "1986-10-24" "1986-10-25" "1986-10-26" "1986-10-26" "1986-10-27" "1986-10-28" "1986-10-29""...

所以出于某种原因,它重复了 26 日,我该如何避免这种情况?

So for some reason it repeats the 26th, how can I avoid that?

推荐答案

该错误在 xts 中.该函数使用 seq.POSIXct,并且可以通过以下方式产生相同的行为:

The bug is in xts. That function uses seq.POSIXct, and the same behavior can be produced by:

seq(as.POSIXct("1986-10-01"), as.POSIXct("1986-11-01"), by="day")

更令我惊讶的是 seq.POSIXlt

seq(as.POSIXlt("1986-10-01"), as.POSIXlt("1986-11-01"), by="day")

但是这种行为在 seq.POSIXt 中有详细记录,并且有使用 by="DSTday" 的规定,xts 作者可能应该在天是隐式间隔的情况下使用它.临时解决方法是:

But that behavior is well documented in seq.POSIXt and there is a provision for using by="DSTday" which the xts authors should probably have used for the situation when days are the implicit interval. The temporary workaround is:

timeBasedSeq("19860601/19861231")[ !duplicated(timeBasedSeq("19860601/19861231") ]

或更紧凑:

unique(timeBasedSeq("19860601/19861231"))

这篇关于timeBasedSeq 函数重复它创建的一些日子!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆