EdwinTh / padr

Padding of missing records in time series
https://edwinth.github.io/padr/
Other
132 stars 12 forks source link

padding timeseries with sub-second intervals #93

Closed blongworth closed 5 months ago

blongworth commented 5 months ago

I have a dataset recorded at 16Hz with missing rows (gap in timestamps). Can padr be used to pad this to a regular timeseries? This doesn't work:

library(padr)
now <- as.POSIXct("2024-03-01")
x <- data.frame(time = seq(now, now + 1, 1/4), value = 1:5)
y <- x[-3,]
y |> pad()
#> Error: The specified interval is invalid for the datetime variable.
#>   Not all original observation are in the padding.
#>   If you want to pad at this interval, aggregate the data first with thicken.
y |> thicken(1/4)
#> Error in strsplit(interval_string, " "): non-character argument

Created on 2024-03-20 with reprex v2.1.0

There are no ascii by arguments to seq.POSIXt() smaller than second, but supplying a number works for creating sub-second sequences (see above data generation).

EdwinTh commented 5 months ago

The interval of your example data is is second and on this interval there is no observation missing from the data. pad does work for the following example

now <- as.POSIXct("2024-03-01 00:00:03")
x <- data.frame(time = seq(now, as.POSIXct("2024-03-01 00:00:06"), by = "sec"), value = 1:4)
y <- x[-3,]
pad(y)

Thicken does not work because you need to specify a character for the interval, in the example you give a numeric. Moreover, applying thicken to this data has no use because it is already at the lowest interval supported by padr (the second).

blongworth commented 5 months ago

The seq() call from my example produces a sequence from 2024-03-01 00:00:00.00 to 2024-03-01 00:00:01, with five elements 1/4 s apart.

seq(now, now + 1, 1/4)

I was hoping I was missing a way that padr could work with arbitrary intervals, like the 1/4 passed to seq() instead of "sec", "hour", etc.

It sounds like the answer is that padr only supports intervals 1 second or greater.

EdwinTh commented 5 months ago

Yes that conlusion is correct