Skip to contents

A generic function to force sorted time vectors to be unique. Useful for high-frequency time-series where original time-stamps may have identical values. For the case of xts objects, the default eps is set to ten microseconds. In practice this advances each subsequent identical time by eps over the previous (possibly also advanced) value.

Usage

is.index.unique(x)

is.time.unique(x)

make.index.unique(x, eps = 1e-06, drop = FALSE, fromLast = FALSE, ...)

make.time.unique(x, eps = 1e-06, drop = FALSE, fromLast = FALSE, ...)

Arguments

x

An xts object, or POSIXct vector.

eps

A value to add to force uniqueness.

drop

Should duplicates be dropped instead of adjusted by eps?

fromLast

When drop = TRUE, fromLast controls which duplicated times are dropped. When fromLast = FALSE, the earliest observation with an identical timestamp is kept and subsequent observations are dropped.

...

Unused.

Value

A modified version of x with unique timestamps.

Details

The returned time-series object will have new time-stamps so that isOrdered(.index(x)) evaluates to TRUE.

Note

Incoming values must be pre-sorted, and no check is done to make sure that this is the case. ‘integer’ index value will be coerced to ‘double’ when drop = FALSE.

See also

Author

Jeffrey A. Ryan

Examples


ds <- options(digits.secs=6) # so we can see the change

x <- xts(1:10, as.POSIXct("2011-01-21") + c(1,1,1,2:8)/1e3)
x
#>                            [,1]
#> 2011-01-21 00:00:00.000999    1
#> 2011-01-21 00:00:00.000999    2
#> 2011-01-21 00:00:00.000999    3
#> 2011-01-21 00:00:00.002000    4
#> 2011-01-21 00:00:00.003000    5
#> 2011-01-21 00:00:00.003999    6
#> 2011-01-21 00:00:00.005000    7
#> 2011-01-21 00:00:00.006000    8
#> 2011-01-21 00:00:00.006999    9
#> 2011-01-21 00:00:00.007999   10
make.index.unique(x)
#>                            [,1]
#> 2011-01-21 00:00:00.000999    1
#> 2011-01-21 00:00:00.001000    2
#> 2011-01-21 00:00:00.001001    3
#> 2011-01-21 00:00:00.002000    4
#> 2011-01-21 00:00:00.003000    5
#> 2011-01-21 00:00:00.003999    6
#> 2011-01-21 00:00:00.005000    7
#> 2011-01-21 00:00:00.006000    8
#> 2011-01-21 00:00:00.006999    9
#> 2011-01-21 00:00:00.007999   10

options(ds)