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

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

    I think this would solve the problem:

    df = data.frame(read.csv("data.csv"))
    # Split the dataset into 80-20
    numberOfRows = nrow(df)
    bound = as.integer(numberOfRows *0.8)
    train=df[1:bound ,2]
    test1= df[(bound+1):numberOfRows ,2]
    

提交回复
热议问题