I have hourly data like the sample below that I am trying to create a time-series from and use the window function with. My end goal is to use this to train an Arima model. I'm having a hard time getting ts()
or window()
to work with my date time format. I've also tried using msts()
but couldn't get it to work with the date time format. I have gotten xts()
to work, but it doesn't seem to work correctly with the window()
or Arima()
.
Is it possible to use this date time format with ts()
and the window()
function? Any tips are greatly appreciated.
Code:
tsData <- ts(SampleData$MedTime[1:24],start='2015-01-01 00:00', frequency=168)
train <- window(tsData,end='2015-01-01 15:00')
Edit Note The data for this problem has been truncated to only 24 observations from the initial 525 provided. As a result, the window()
call has been modified as well to a time within the truncated range.
Data:
dput(SampleData[1:24,c("DateTime","MedTime")])
SampleData = structure(list(DateTime = c("2015-01-01 00:00", "2015-01-01 01:00", "2015-01-01 02:00", "2015-01-01 03:00", "2015-01-01 04:00", "2015-01-01 05:00", "2015-01-01 06:00", "2015-01-01 07:00", "2015-01-01 08:00", "2015-01-01 09:00", "2015-01-01 10:00", "2015-01-01 11:00", "2015-01-01 12:00", "2015-01-01 13:00", "2015-01-01 14:00", "2015-01-01 15:00", "2015-01-01 16:00", "2015-01-01 17:00", "2015-01-01 18:00", "2015-01-01 19:00", "2015-01-01 20:00", "2015-01-01 21:00", "2015-01-01 22:00", "2015-01-01 23:00"), MedTime = c(11, 14, 17, 5, 5, 5.5, 8, NA, 5.5, 6.5, 8.5, 4, 5, 9, 10, 11, 7, 6, 7, 7, 5, 6, 9, 9)), .Names = c("DateTime", "MedTime"), row.names = c(NA, 24L), class = "data.frame")