I'm trying since more than an hour to split randomly my data frame into two frame based on a given percentage, however, I can't make it work i don't know why.
I saw those posts :
- How to split data into training/testing sets using sample function in R program
- R: How to split a data frame into training, validation, and test sets?
- How can divide a dataset based on percentage?
What I want is basically to take as input a data frame df, and a real number α ∈ (0, 1) and returns a list consisting of two data frames df1 and df2. df1 is finally (a * 100)% of df, and df2 the rest of df, the unselected rows.
For example, if df has 100 rows, and α = 0.4, then df1 will consist of 40 randomly selected rows of df, and df2 will consist of the other 60 rows.
I could do it with a big function and loops etc, make my algorithm, but I'm pretty sure, another way to do it should exists and I would like to share this solution with the community !
Thank for your help !