vendredi 30 octobre 2020

R Radom data split based on 2 columns

I have data like this (column ObjectID and Cost) and I normally split data using:

sample.split(data$Cost, SplitRatio=0.7)

But in this case I want keep 'Cost' as relative ratio but also I want to use ObjectID - so each ObjectID can be only in test or train group. How to random split this?

ObjectID Cost   Type
12345   1624    Test
12345   1175    Test
12345   1049    Test
12345   1733    Test
11111   1945    Train
11111   1989    Train
22222   1448    Test
22222   1815    Test
22222   1244    Test
33333   1355    Train
33333   1134    Train
44444   1478    Train
44444   1082    Train
44444   1147    Train
44444   1290    Train
55555   1383    Train
55555   1378    Train
55555   1288    Train



Aucun commentaire:

Enregistrer un commentaire