vendredi 15 novembre 2019

How to divide data frame in r in groups of equal number of records and split dat randomly & equally in two data frames

I have some data that contains about 30000 records. I want to divide the data into groups of 288 records. And then sort the data into test_data & train_data separate data frames where first 4 records are stored into train_data while 5th record into test_data, sequentially and randomly. Randomly in a way any day of the 5 days is saved into test_data & rest 4 goes into train_data.

How this can be achieved ?

Sampel data:

timestamp               var1      var2
--------------------------------------
01-01-2019 18:00:00      1.2       21
01-01-2019 18:05:00      2.3       32
01-01-2019 18:10:00      3.4       43
01-01-2019 18:15:00      4.5       54
01-01-2019 18:20:00      5.6       65



Aucun commentaire:

Enregistrer un commentaire