Question

I have encountered a duplicate index warning/error in zoo. I spent some time to troubleshoot, and it came down to the following data/snippet:

Lines = "Index,dbt,rh,dpt,wind.mph,gust.mph,wind.dir,voltage,klux,fc
2008-03-09 01:00:00,37.96,77.25,31.60,4.16,5.39,247,0.00,28.283,2643.28
2008-03-09 02:00:00,37.20,77.25,30.90,0.00,0.43,244,0.00,28.283,2643.28"

x <- read.table(header=T,text=Lines,sep=",")

library(zoo)

z = zoo(x[,2:10],as.POSIXct(x$Index))

If I run the above, I got the following warning:

Warning message:
In zoo(x[, 2:10], as.POSIXct(x$Index)) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique

I was wondering what is wrong with the data/index. They are in fact different.

However, the following command:

library(xts)
make.index.unique(index(z))

gave a puzzling result:

[1] "2008-03-09 01:00:00 MST" "2008-03-09 01:00:00 MST"

Did the above command just make the indeces duplicates? Can anybody enlighten me on how this works?

Was it helpful?

Solution

The issue is not so much with zoo as it is with the arguments to as.POSIXct

Have a look at as.POSIXct(x$Index) and you will see that it is not giving the results you require.

Giving as.POSIXct a time zone will help.


Compare:

as.POSIXct(x$Index)
#  [1] "2008-03-09 01:00:00 EST" "2008-03-09 01:00:00 EST"

as.POSIXct(x$Index, tz = "GMT")
#   [1] "2008-03-09 01:00:00 GMT" "2008-03-09 02:00:00 GMT"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top