从R中的POSIXct提取2位数小时 [英] Extracting 2 digit hour from POSIXct in R
本文介绍了从R中的POSIXct提取2位数小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从R中的 POSIXct
时间提取小时,但是取回2位数的答案。
I would like to extract the hour from a POSIXct
time in R, but retrieve the 2 digit answer.
例如,
test=as.POSIXct("2015-03-02 03:15:00")
test
[1] "2015-01-02 03:15:00 GMT"
month(testing)
[1] 1
hour(testing)
[1] 3
结果给出了相关的月份和小时,但是我想看到 01
和 03
而不是 1
和 3
。
The results give the relevant month and hour, but I would like to see 01
and 03
instead of just 1
and 3
.
推荐答案
尝试这样做:
strftime(test, format="%H")
提取小时和
strftime(test, format="%m")
月份
这篇关于从R中的POSIXct提取2位数小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文