问题
I would like to extract the hour from a POSIXct
time in R, but retrieve the 2 digit answer.
For example,
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
The results give the relevant month and hour, but I would like to see 01
and 03
instead of just 1
and 3
.
回答1:
Try to do this:
strftime(test, format="%H")
to extract hours and
strftime(test, format="%m")
for month
来源:https://stackoverflow.com/questions/35227648/extracting-2-digit-hour-from-posixct-in-r