Need help separating my in-sample data and out-sample data!

Finding it difficult to work out how to separate the data. I have 2 variables - time and GDP. There are 478 observations, each of which count for a month of the year (1 observation = 1 month). How am I able to split the data into different sections to view both in-sample data and out-sample data separately?

I need to recreate 2 tables. Table 1 must contain data from 1980-2013 (in-sample period) and Table 2 must show data from 2014 to 2019 (out-sample period).

It is difficult to give specific advice without knowing more about the structure of your data. Please run the command


with NameOfYourDataFrame replaced by the actual name of the table. Paste the result into a response on the forum and be sure to put lines with three back tics, ```, before and after the information you paste so that it will be formatted as code.

$ Time  : POSIXct, format: "1980-01-01" "1980-02-01" ...
$ INDPRO: num  53.5 53.5 53.3 52.2 51 ... ```

Thanks for your help. Very grateful!

Here is some additional information:

The in-sample period is from Feb 1980 to Dec 2013, and the out-of-sample period is from Jan 2014 to Oct 2019.

Thanks FJCC

The lubridate package makes it easy to handle dates and times. I used its ymd_hms function in the following example. Let's say your data are named DF:

BORDER <- lubridate::ymd_hms("2014-01-01 00:00:00")
InSample <- DF[DF$Time < BORDER, ]
OutOfSample <- DF[DF$Time >= BORDER, ]
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.