I need to backtest a predictive model in R by using cross-validation methodology.
So, I should select 4 out of 5 of the total observations in the dataset for training purposes and use the remaining one for testing.
Now, let's assume x
is the total dataset, composed by 100 observations, I know that you can select a sub-sample x1
in R by typing:
x1 <- x[1:80, ]
In this way, I selected the first 4 out of fifth observations in the dataset.
What I should do to select the second 4 out of fifth sub-sample, that is the observations [1:20]
and [40:100]
?
Any hint will be appreciated. In the case the question will result to be unclear, ping me in the comment, please.