Closed ckatsulis closed 7 years ago
I think the problem is with your data. The Note section of ?make.index.unique
says:
Incoming values must be pre-sorted, and no check is done to make sure that this is the case. If the index values are of storage.mode 'integer', they will be coerced to 'double' if drop=FALSE.
Look at the timestamp for rows 17 and 18 of orderData
:
17 112.47300 2000 1 NA NA 2017-07-17 09:32:00
18 0.96099 6000 1 NA NA 2017-07-17 09:31:00
Those are not sorted, and I think that's the cause of the behavior you see. I can't do more than guess, because your example isn't fully reproducible. You need to provide the object structure (via dput()
) in order for me to run your examples.
good eyes... missed that part. it should be resolved on our end anyway as we have some latent time stamp in one of our logging stats that we are changing. thanks for the quick response
On Sun, Aug 13, 2017 at 12:36 PM, Joshua Ulrich notifications@github.com wrote:
I think the problem is with your data. The Note section of ?make.index.unique says:
Incoming values must be pre-sorted, and no check is done to make sure that this is the case. If the index values are of storage.mode 'integer', they will be coerced to 'double' if drop=FALSE.
Look at the timestamp for rows 17 and 18 of orderData:
17 112.47300 2000 1 NA NA 2017-07-17 09:32:00 18 0.96099 6000 1 NA NA 2017-07-17 09:31:00
Those are not sorted, and I think that's the cause of the behavior you see. I can't do more than guess, because your example isn't fully reproducible. You need to provide the object structure (via dput()) in order for me to run your examples.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joshuaulrich/xts/issues/206#issuecomment-322055545, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKwqt5AU_9ZVvnjtNyaTbj4-fsA20tfks5sXzQNgaJpZM4O1vaA .
So even after presorting and making unique of original data set, when I run make.index.unique()
on the resulting xts
object, I receive the following:
orderData = orderData[order(orderData$DesiredTime),]
orderData$DesiredTime = make.index.unique(orderData$DesiredTime, eps = 1e-03)
xtsWrite = xts::xts(orderData[,fields], orderData$DesiredTime)
xtsWrite = xts::make.index.unique(xtsWrite)
names(xtsWrite) = fields
> isOrdered(orderData$DesiredTime)
> xts::is.index.unique(xtsWrite)
[1] TRUE
> xts::isOrdered(xtsWrite)
[1] FALSE
Thank you for the reproducible example! orderData$DesiredTime
is the number of seconds since the epoch, not POSIXct
. So I'm not sure how your xts()
call works. I've used .POSIXct()
to convert it to POSIXct
.
orderData <- dget("https://github.com/joshuaulrich/xts/files/1220681/orderData.txt")
fields <- "OrdId"
orderData$DesiredTime <- make.index.unique(orderData$DesiredTime, eps = 1e-03)
xtsWrite <- xts::xts(orderData[,fields], .POSIXct(orderData$DesiredTime))
xtsWrite <- xts::make.index.unique(xtsWrite)
names(xtsWrite) <- fields
isOrdered(orderData$DesiredTime)
# [1] FALSE
xts::is.index.unique(xtsWrite)
# [1] TRUE
xts::isOrdered(xtsWrite) # Expect FALSE, since first 3 OrdId are 2, 4, 3.
# [1] FALSE
xts::isOrdered(.index(xtsWrite)) # Expect TRUE, index should be unique and increasing
# [1] TRUE
So I don't see anything wrong with the behavior of make.index.unique()
or isOrdered()
. Or am I missing something?
Good catch, orderData$DesiredTime
is supposed to be POSIXct, so I'll blame that on me. User error!
Thanks for your help sir!
Description
Per the documentation for make.index.unique():
Expected behavior
When I run:
I would expect:
Instead I receive
Minimal, reproducible example
Session Info