本文介绍了将数据帧分割成固定尺寸的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆长度不等的数据帧,范围从大约15,000至50万。对于这些数据帧中的每一个,我想将它们分成更小的数据帧,每个数据帧都有300行,我将进行进一步的处理。我该怎么做?



这个()提供部分答案,但不起作用,因为并不是所有的数据帧的长度都是300的倍数



如果可以提供plyr和非plyr解决方案,将非常感激。



谢谢

解决方案

我不明白为什么需要plyr解决方案。 split 工作得很好,甚至哈利自己也没有提出一个plyr / reshape2解决方案,当他看到以前的问题:

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

会产生警告,但是由于您期待不均匀的分割结果,您应该忽略它。


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 smaller data frames each with 300 rows which I would do further processing on. How can I do this?

This (Split up a dataframe in R by number of rows) provides a partial answer, but it doesn't work because not all my data frames have length that are multiples of 300.

Would greatly appreciate it if a plyr and non-plyr solution can both be provided.

Thank you!

解决方案

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.

这篇关于将数据帧分割成固定尺寸的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 17:56