[R] Milisecond problem in as.POSIXct ?
ce
zadig_1 at excite.com
Thu Jun 11 02:41:44 CEST 2015
Dear all,
my main problem is with miliseconds. I have an array :
library(xts)
options(digits.secs = 3)
> x
[1] "2015-06-10 10:22:06.389 EDT" "2015-06-10 10:22:07.473 EDT"
[3] "2015-06-10 10:22:08.717 EDT" "2015-06-10 10:22:09.475 EDT"
> x[1]
[1] "2015-06-10 10:22:06.38 EDT"
> x[2]
[1] "2015-06-10 10:22:07.473 EDT"
why it cuts last digit of miliseconds 389 to 38 ? ( it doesn't cut 473 !! )
I try to dump it to post here:
> dump("x",file=stdout())
x <-
structure(c(1433946126.39, 1433946127.474, 1433946128.717, 1433946129.476
), tzone = "", tclass = c("POSIXct", "POSIXt"), class = c("POSIXct",
"POSIXt"))
new array becomes :
> x
[1] "2015-06-10 10:22:06.390 EDT" "2015-06-10 10:22:07.473 EDT"
[3] "2015-06-10 10:22:08.717 EDT" "2015-06-10 10:22:09.476 EDT"
this time first milisecond 389 became 390 ? and last element 475 became 476 ?
I do some more tests :
as.POSIXct("2015-06-10 10:22:07.473",format='%Y-%m-%d %H:%M:%OS')
[1] "2015-06-10 10:22:07.473 EDT"
is correct, but :
as.POSIXct("2015-06-10 10:22:06.389",format='%Y-%m-%d %H:%M:%OS')
[1] "2015-06-10 10:22:06.388 EDT"
why miliseconds turn to 388 instead of 389 ?
or
as.POSIXct("2015-06-10 10:22:07.478",format='%Y-%m-%d %H:%M:%OS')
[1] "2015-06-10 10:22:07.477 EDT"
why it shows 477 instead of 478
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-suse-linux-gnu (64-bit)
Running under: openSUSE 13.2 (Harlequin) (x86_64)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xts_0.9-7 zoo_1.7-12
loaded via a namespace (and not attached):
[1] tools_3.2.0 grid_3.2.0 lattice_0.20-31
More information about the R-help
mailing list