I've seen a lot of posts in regards to subsetting time series through specific date requirements, but I can not figure out how to subset based on integers. Consider:
# create dummy data
data <- ts(seq_len(96), start=c(2009,1), f=12)
# create training data
training.set <- ts(data[1:(length(data)-8)], start=c(2009,1), frequency=12)
# I want to remove the last 8 values (or any integer) and use that as a test set while retaining the correct dates
test.set <- ts(data[(length(data)-8+1):length(data)])
test.set # start/end aren't retained for the test set
Time Series:
Start = 1
End = 8
Frequency = 1
[1] 89 90 91 92 93 94 95 96
I know I can specify the new start/end dates on the test set explicitly, but that won't work for my use. I'm trying to find a way to automatically do that so a function I'm writing can handle any dates based on the input time series and subset both training and test sets (based on any integer < length of the input series).