2

I have a xts time series that contains a column "timeInt" that contains the beginning of time interval expressed as the number of millisecond. The end of the time interval can be obtained by adding 600000 milliseconds (10 minutes) to this value. The range of my data, then, should have a periodicity of 10 minutes for a day (from 00.00 to 23:50).

So I have this xts

>head(sms, n=8)
            squareId      smsIN     smsOUT
2013-12-01        1 0.11098917 0.16621437
2013-12-01        1         NA         NA
2013-12-01       10 0.05482169 0.09364877
2013-12-01       10         NA         NA
2013-12-01      100 0.04077425         NA
2013-12-01     1000 0.65962509 0.73610317
2013-12-01    10000 0.01432295         NA

As you can see I have a field "squareId" that is referred to the a cell in a map. There are 1000 cells

>range(sms$squareId)
[1]     1 10000

The problem is that I think I can't get the correct periodicity for my data

>periodicity(sms)
0 seconds periodicity from 2013-12-01 to 2013-12-01 23:50:00 

Indeed, if I plot the xts I get this (I plot only one hour cause I have a large xts)

>plot.zoo(sms['T08:00/T09:00',-c(1)], plot.type = 'multiple' )

enter image description here

I tried to adjust the index applying the to.period() function

>to.period(sms, period='seconds', OHLC = F)

and it seems that I get a correct periodicity

10 minute periodicity from 2013-12-01 to 2013-12-01 23:50:00 

Plotting it seems all ok

enter image description here

but I realize that applying to.period() many squareId are lost

> range(mi.dec01_xts$squareId)
[1] 9895 9999

The question is, how can adjust my xts of 10 min interval correctly? How can I apply the to.period() function without lose the squareId information?

EDIT

Here I paste a reproducible example using reproduce.R

This is what the sample looks like:

                squareId      smsIN     smsOUT
2013-12-01 00:00:00        1 0.11098917 0.16621437
2013-12-01 00:00:00        1         NA         NA
2013-12-01 00:00:00       10 0.05482169 0.09364877
2013-12-01 00:00:00       10         NA         NA
2013-12-01 00:00:00      100 0.04077425         NA
2013-12-01 00:00:00      100 0.16140787 0.12063361
2013-12-01 00:00:00     1000 0.65962509 0.73610317
2013-12-01 23:50:00     9998         NA         NA
2013-12-01 23:50:00     9999 0.17198955         NA
2013-12-01 23:50:00     9999 0.08876703         NA




sms <- structure(c(1, 1, 10, 10, 100, 100, 1000, 9998, 9999, 9999,
0.110989169614244,NA, 0.0548216917417026, NA, 0.0407742548283372,
0.161407867214471,0.659625094191792, NA, 0.171989545769285,
0.0887670343758315,0.166214368861216, NA, 0.0936487714299922, NA, NA,
0.120633612386134,0.736103165655047, NA, NA, NA),
.indexCLASS = c("POSIXlt", "POSIXt"), tclass = c("POSIXlt", "POSIXt"),
.indexTZ = "UTC", tzone = "UTC", class = c("xts","zoo"),
index = structure(c(1385856000, 1385856000, 1385856000,1385856000,
1385856000, 1385856000, 1385856000, 1385941800, 1385941800,1385941800),
tzone = "UTC", tclass = c("POSIXlt", "POSIXt")), .Dim = c(10L,3L),
.Dimnames = list(NULL, c("squareId", "smsIN", "smsOUT"))) 
Community
  • 1
  • 1
andriatz
  • 622
  • 2
  • 9
  • 22
  • 2
    Please provide a [reproducible example](http://stackoverflow.com/q/5963269/271616). – Joshua Ulrich Apr 11 '17 at 23:09
  • i paste it in the bottom of the post. I use this script : "https://raw.github.com/rsaporta/pubR/gitbranch/reproduce.R" – andriatz Apr 12 '17 at 10:04
  • The problem is still not clear. You have many observations with the same timestamp. `periodicity()` works by looking at the median difference between timestamps, which is likely zero. And it seems like you want to aggregate somehow, but that isn't clear either, since you don't provide an example of your expected output given the sample input. – Joshua Ulrich Apr 12 '17 at 19:31

0 Answers0