R/zoo: index entries in ‘order.by’ are not unique

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I have a .csv file containing 4 columns of data against a column of dates/times at one-minute intervals. Some timestamps are missing, so I'm trying to generate the missing dates/times and assign them NA values in the Y columns. I have previously done this with other .csv files with exactly the same formatting, with no issues. The code is:

# read the csv file har10 = read.csv(fpath, header=TRUE);  # set date har10$HAR.TS

My data looks like this (for an entire year, more or less) after conversion to POSIXct, which seems to go fine:

                    HAR.TS        C1       C2         C3        C4 1      2010-01-01 00:00:00 -4390.659 5042.423 -2241.6344 -2368.762 2      2010-01-01 00:01:00 -4391.711 5042.056 -2241.1796 -2366.725 3      2010-01-01 00:02:00 -4390.354 5043.003 -2242.5493 -2368.786 4      2010-01-01 00:03:00 -4390.337 5038.570 -2242.7653 -2371.289 

When I the "convert to zoo" step I get the following error:

 Warning message:  In zoo(har10[, -1], har10[, 1]) :    some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 

I have checked for duplicated entries but get no results:

> anyDuplicated(har10) [1] 0 

Any ideas? I have no idea why I'm getting this error on this file, but it has worked for previous ones. Thanks!


EDIT: Reproducable form:

EDIT 2: Have to remove the data/code, sorry!

回答1:

anyDuplicated(har10) tells you if any complete rows are duplicated. zoo is warning about the index, so you should run anyDuplicated(har10$HAR.TS). sum(duplicated(har10$HAR.TS)) will show there are almost 9,000 duplicate datetimes. The first duplicate is around row 311811, where 10/08/19 13:10 appears twice.



回答2:

And to handle duplicated indices (see ?zoo and ?aggregate.zoo)

## zoo series with duplicated indexes z3 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!