xts对象中的日期重复导致错误的索引编制

时间:2018-10-09 18:00:20

标签: r xts zoo

我有用户数据和重复的日期,例如用户访问网站。 示例:

require(zoo)
require(xts)

test <- structure(list(timestamp = c("2013-03-06 01:00:00", "2014-07-06 21:00:00", 
                                  "2014-07-31 23:00:00", "2014-08-09 17:00:00", "2014-08-14 20:00:00", 
                                  "2014-08-14 22:00:00", "2014-08-16 15:00:00", "2014-08-19 02:00:00", 
                                  "2014-12-28 18:00:00", "2015-01-17 17:00:00"), user = c(1, 2, 
                                                                                          2, 3, 3, 3, 3, 3, 4, 4)), .Names = c("timestamp", "user"), row.names = c("220667", 
                                                                                                                                                                   "331481", "422653", "629430", "378111", "646137", "558638", "151641", 
                                                                                                                                                                   "599370", "482750"), class = "data.frame")  

如果我创建一个xts对象,然后使用其自己的索引对其进行访问,则会得到不同的数据。我在这里做什么错了?

testXts <- xts(x=test,order.by = as.Date(test$timestamp))
testXts[index(testXts)]#Different (wrong) data. Why ?

0 个答案:

没有答案