Time sequence (hour)

I tried:

seq( from=as.POSIXct("2012-1-1 0", tz="UTC"), to=as.POSIXct("2012-1-3 23", tz="UTC"), by="hour" ) 

But I get only 1 hour (0:00:00) for the last day, and not 24 hours, in fact, any hour of the day only leads to one hour (0:00:00), and I want to have 2012-1-4.

+6
source share
3 answers

Specify the time in full?

 seq( from=as.POSIXct("2012-1-1 0:00", tz="UTC"), to=as.POSIXct("2012-1-3 23:00", tz="UTC"), by="hour" ) 
+8
source

You can specify the format:

 seq( from=as.POSIXct("2012-1-1 0","%Y-%m-%d %H", tz="UTC"), to=as.POSIXct("2012-1-3 23", "%Y-%m-%d %H", tz="UTC"), by="hour" ) 
+3
source

You did not use the standard format for dates. See ?as.POSIXct .

try it

 seq(from=as.POSIXct("2012-01-01 00:00:00", tz="UTC"), to=as.POSIXct("2012-01-03 23:00:00", tz="UTC"), by="hour") 
+2
source

Source: https://habr.com/ru/post/923252/


All Articles