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

前端 未结 24 2028
猫巷女王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:45

    I will split 'a' into train(70%) and test(30%)

        a # original data frame
        library(dplyr)
        train<-sample_frac(a, 0.7)
        sid<-as.numeric(rownames(train)) # because rownames() returns character
        test<-a[-sid,]
    

    done

提交回复
热议问题