Q:

Generate frames from days

In my data set the days have this format:
day
2000-01-01 00:00:00
2000-01-01 01:00:00
2000-01-01 02:00:00
2000-01-01 03:00:00

We call the dataframe day.
I want to generate a dataframe for days and I am using this:
n=12
day <- as.Date( tail( day$day , 1 ) , format = "Y-%m-%d %H:%M:%S" )+1:n

However the problem is that this gives me 2000-01-01 instead of 2000-01-01 03:00:00. It doesn't includes the hours only the day.

A:

Either of these will work. You are also missing a % before the Y in your call to as.Date. Note that the integer unit of these datatypes is seconds, so to add an hour to a date/time you need to add multiples of 3600 seconds to the date:
n=12
strptime( "2000-01-01 03:00:00" , format = "%Y-%m-%d %H:%M:%S" )+(1:n)*3600
as.POSIXct( "2000-01-01 03:00:00" , format = "%Y-%m-%d %H:%M:%S" )+(1:n)*3600

I recommend the as.POSIXct method. strptime converts character vectors to class POSIXlt. I am not sure why, but I think many people prefer POSIXct over POSIXlt.
as.POSIXct( tail( days$day , 1 ) , format = "%Y-%m-%d %H:%M:%S" )+(1:n)*3600

