我们可以在 R 中报告时间的详细程度吗?

How detailed can we report time in R?

所以当我使用

>strptime(paste(as.character(as.POSIXct(as.numeric(substr(1438293919327731275,1,10)),origin="1970-01-01")),
+                substr(1438293919327731275,11,13),sep="."),"%Y-%m-%d %H:%M:%OS")
[1] "2015-07-30 17:05:19"

我想知道 substr(14-19) 发生了什么?不管怎样,我们可以报告他们说我们什么时候用这个数字来做情节?

为了回答您的问题,是的,R 图可以处理包括亚秒级分数的 POSIXct 时间:

x <- 1:2
y <- as.POSIXct(c(1438293919.3277, 1438293919.4682),origin="1970-01-01")
#[1] "2015-07-31 08:05:19 EST" "2015-07-31 08:05:19 EST"
plot(y ~ x, yaxt="n")
axis.POSIXct(
  2,
  at=as.POSIXct(axTicks(2),origin="1970-01-01"), format="%OS2",
  las=2, cex.axis=0.7
)

正如 Joshua Ulrich 所说,秒的小数部分不会丢失, 但默认不显示。如果你想看到小数部分,设置 选项 "digit.secs" 到所需的小数位数。 但至少在我的系统上我不能得到超过 7 位小数:

#============================================================
# With option "digit.secs"=NULL

options(digits.secs=NULL)

t1 <- as.POSIXct(as.numeric(substr(1438293919327731275,1,10)),
                 origin="1970-01-01")

t2 <- strptime(paste(as.character(t),
                     substr(1438293919327731275,11,13),
                     sep="."),
               "%Y-%m-%d %H:%M:%OS")

t3 <- strptime(paste(as.character(t),
                     substr(1438293919327731275,11,19),
                     sep="."),
               "%Y-%m-%d %H:%M:%OS")

t1
t2
t3

t2-t1
t3-t1

#==============================================================
# With option "digit.secs"=9

options(digits.secs=9)

t1 <- as.POSIXct(as.numeric(substr(1438293919327731275,1,10)),
                 origin="1970-01-01")

t2 <- strptime(paste(as.character(t),
                     substr(1438293919327731275,11,13),
                     sep="."),
               "%Y-%m-%d %H:%M:%OS")

t3 <- strptime(paste(as.character(t),
                     substr(1438293919327731275,11,19),
                     sep="."),
               "%Y-%m-%d %H:%M:%OS")

t1
t2
t3

t2-t1
t3-t1

结果:

> #============================================================
> # With option "digit.secs"=NULL
> 
> options(digits.secs=NULL)

> t1 <- as.POSIXct(as.numeric(substr(1438293919327731275,1,10)),
+                  origin="1970-01-01")

> t2 <- strptime(paste(as.character(t),
+                      substr(1438293919327731275,11,13),
+                      sep="."),
+                "% ..." ... [TRUNCATED] 

> t3 <- strptime(paste(as.character(t),
+                      substr(1438293919327731275,11,19),
+                      sep="."),
+                "% ..." ... [TRUNCATED] 

> t1
[1] "2015-07-31 00:05:19 CEST"

> t2
[1] "2015-07-31 00:05:19 CEST"

> t3
[1] "2015-07-31 00:05:19 CEST"

> t2-t1
Time difference of 0.3269999 secs

> t3-t1
Time difference of 0.3277311 secs

> #==============================================================
> # With option "digit.secs"=9
> 
> options(digits.secs=9)

> t1 <- as.POSIXct(as.numeric(substr(1438293919327731275,1,10)),
+                  origin="1970-01-01")

> t2 <- strptime(paste(as.character(t),
+                      substr(1438293919327731275,11,13),
+                      sep="."),
+                "% ..." ... [TRUNCATED] 

> t3 <- strptime(paste(as.character(t),
+                      substr(1438293919327731275,11,19),
+                      sep="."),
+                "% ..." ... [TRUNCATED] 

> t1
[1] "2015-07-31 00:05:19 CEST"

> t2
[1] "2015-07-31 00:05:19.327 CEST"

> t3
[1] "2015-07-31 00:05:19.327731 CEST"

> t2-t1
Time difference of 0.3269999 secs

> t3-t1
Time difference of 0.3277311 secs