mercredi 27 mars 2019

How to randomly split data into three equal sizes?

I have a dataset with 9558 rows from three different projects. I want to randomly split this dataset in three equal groups and assigning a unique ID for each group, so that Project1_Project_2_Project3 becomes Project1, Project2 and Project3.

I have tried many things, and googled codes from people with similar problem as I have. I have used sample_n() and sample_frac(), but unfortunately I can't solve this issue myself :/

I have made an example of my dataset looking like this:


ProjectName <- c("Project1_Project2_Project3")
data <- data.frame(replicate(10,sample(0:1,9558,rep=TRUE)))
data <- data.frame(ProjectName, data)

And the output should be randomly splitted in three equals group of nrow=3186 and then assigned it to the values

ProjectName Count of rows
Project1     3186
Project2     3186
Project3     3186





Aucun commentaire:

Enregistrer un commentaire