dimanche 2 mai 2021

Assign a specific number of random rows into datasets in R

I have a dataset with 54285 observations. What I need is to assign randomly 50% of the rows into another dataframe, 30% into another dataset, and the rest (20%) into another one. This should be done without duplicates. This is an example:

data<-data.frame(numbers=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
data
1
2
3
4
5
6
7
8
9
10
What I expect would be:
df1
5
3
8
1
7

df2
2
4
9

df3
6
10



Aucun commentaire:

Enregistrer un commentaire