Split Data Frame into Rows of Fixed Size

后端 未结 2 1494
说谎
说谎 2020-12-02 00:11

I have a bunch of data frames with varying degrees of length, ranging from approx. 15,000 to 500,000. For each of these data frames, I would like to split them up into smal

相关标签:
2条回答
  • 2020-12-02 00:42

    Something like the following may help

    numBreaks <- nrow(DAT)%/%300 + 1
    for( i in seq(numBreaks)){
      smallDAT <- DAT[((i-1)*300+1):(min(nrow(DAT), i*300)), ]
    .....
    }
    
    0 讨论(0)
  • 2020-12-02 00:55

    I don't understand why a plyr solution is needed. split works perfectly well and even hadley himself didn't suggest a plyr/reshape2 solution when he looked at the earlier question:

    split(dfrm, (0:nrow(dfrm) %/% 300)  # modulo division
    

    Does produce a warning but since you were expecting a non-evenly divisible result you should ignore it.

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