从sys.time获取数字

h.l*_*l.m 2 r concatenation

是否有一种更有效/更优雅的方法来执行以下操作,其中我连接输出的Sys.time()输出中的所有数字

x <- as.character(Sys.time())
paste0(substr(x,0,4),substr(x,6,7),substr(x,9,10),substr(x,12,13),substr(x,15,16),substr(x,18,20))
Run Code Online (Sandbox Code Playgroud)

它可能包括粘贴和崩溃,但不知道如何做到这一点......

And*_*rie 7

您可以使用格式文字strftime()POSIXct对象转换为字符:

strftime(Sys.time(), "%Y%m%d%H%M%S")
[1] "20120910061602"
Run Code Online (Sandbox Code Playgroud)

有关?strftime要使用的字符串文字的详细信息,请参阅.


42-*_*42- 5

我原本以为format是第一选择:

format(Sys.time(), "%Y%m%d%H%M%S")
[1] "20120909231732"
Run Code Online (Sandbox Code Playgroud)