How to split data into training/testing sets using sample function

前端 未结 24 1981
猫巷女王i
猫巷女王i 2020-11-22 10:43

I\'ve just started using R and I\'m not sure how to incorporate my dataset with the following sample code:

sample(x, size, replace = FALSE, prob = NULL)
         


        
24条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 10:53

    scorecard package has a useful function for that, where you can specify the ratio and seed

    library(scorecard)
    
    dt_list <- split_df(mtcars, ratio = 0.75, seed = 66)
    

    The test and train data are stored in a list and can be accessed by calling dt_list$train and dt_list$test

提交回复
热议问题