r - issues when trying to make indices unique in xts -
i have following xts object:
options("digits.secs" = 1) ex <- structure(c(na, -63l, na, na, na, na, na, 0l, na, na, na, na, na, 1l, na, na, na, na), .dim = c(6l, 3l), .dimnames = list(null, c("v2", "v3", "v4")), index = structure(c(1366088402.46, 1366088402.46, 1366088402.463, 1366088402.463, 1366088469.697, 1366088469.697), tzone = "", tclass = c("posixct", "posixt")), class = c("xts", "zoo"), .indexclass = c("posixct", "posixt"), tclass = c("posixct", "posixt"), .indextz = "", tzone = "") ex <- make.index.unique(ex, drop = true, fromlast = true)
however, resulting xts object doesn't have unique indices. i've tried using strptime
format="...%os1"
, returns na
values. above code intuitively doesn't make sense me because i'm using output options try , truncate dates.
i've searched how other people handling fractional timestamps, , results seem consistent above. why isn't %os1
working me, , options
correct way handle this? want time index internally truncated @ specified increments, index shouldn't change every time set options("digits.secs")
new.
> options("digits.secs"=3) > head(ex) v2 v3 v4 2013-04-16 00:00:02.460 na na na 2013-04-16 00:00:02.460 -63 0 1 2013-04-16 00:00:02.463 na na na 2013-04-16 00:00:02.463 na na na 2013-04-16 00:01:09.697 na na na 2013-04-16 00:01:09.697 na na na > ex <- align.time(ex, n = 0.1) > head(ex) v2 v3 v4 2013-04-16 00:00:02.5 na na na 2013-04-16 00:00:02.5 -63 0 1 2013-04-16 00:00:02.5 na na na 2013-04-16 00:00:02.5 na na na 2013-04-16 00:01:09.7 na na na 2013-04-16 00:01:09.7 na na na > ex <- make.index.unique(ex, drop = true, fromlast = true) > head(ex) v2 v3 v4 2013-04-16 00:00:02.5 na na na 2013-04-16 00:01:09.7 na na na 2013-04-16 00:01:09.7 -65.5 -7500 0.25 2013-04-16 00:01:13.5 -64.0 -7500 0.25 2013-04-16 00:01:15.4 -64.0 -10000 0.20 2013-04-16 00:01:24.9 -64.0 -10000 0.20
as can see data getting cut down third in length, in first few rows there repeated time index @ 00:01:09.7.
try modify format this:
strptime(sys.time(), format = "%y-%m-%d %h:%m:%s")
the 'format = "%y/%m/%d %h:%m:%s"'output na:
strptime(sys.time(), format = "%y/%m/%d %h:%m:%s")
Comments
Post a Comment