Reputation: 1866
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
.
Upvotes: 3
Views: 6411
Reputation: 126
Try to do this:
strftime(test, format="%H")
to extract hours and
strftime(test, format="%m")
for month
Upvotes: 8