mercredi 6 mai 2020

Create two datasets by equally dividing rows based on postal codes in R

I have a dataset with customer codes, customer name, and postal codes. The dataset has 149130 rows. I want to equally split it into two datasets (each of 74565 rows) and export in excel. However I want to make sure that if there are two customers for one postal code - one goes to dataset1 and the other goes to dataset2. The rest can be a random selection of customers. I am new to r and have tried various train/test and sample codes - however I haven't been able to achieve the result needed.

To summarize - I am trying to create 2 random samples out of the dataframe but want to make sure that if there are more than 2 customers under a certain postal code - they should be equally split between the two samples.

TIA




Aucun commentaire:

Enregistrer un commentaire