Splitting data randomly in R

后端 未结 1 1229
情书的邮戳
情书的邮戳 2021-01-24 08:42

I have a data in .csv with 19020 observations. I need to split the data randomly into parts of 13020, 3000 and 3000 in R. I have tried the following code but it doesn\'t help me

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 09:31

    Can you use something like

    index <- sample(19020)
    part1 <- HW2[index[1:13020],]
    part2 <- HW2[index[13021:16020],]
    part3 <- HW2[index[16021:19020],]
    

    Edited first line according to Pierre's suggestion

    0 讨论(0)
提交回复
热议问题