R:将数据帧分为3部分 [英] R: split dataframe into 3 parts

查看:92
本文介绍了R:将数据帧分为3部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据帧分为3部分。(4352行)
我尝试了 split(df,1:3)并完成了工作但是当我尝试查看分割df时,会出现错误。

I am trying to divide the dataframe into 3 parts.(4352 rows) I tried split(df,1:3) and it does the job but when I try view the split df, it gives an error.

splitdf<-split(df, f = rep_len(1:3, nrow(df)   ))   
View(splitdf)




视图错误:参数暗示行数不同:1451、1450 *

Error in View : arguments imply differing number of rows: 1451, 1450*

我错过了什么吗?

推荐答案

我们可以在<$ c中使用 length.out 自变量$ c> rep

We can use the length.out argument in rep

split(df, rep(1:3, length.out = nrow(df), each = ceiling(nrow(df)/3)))

这篇关于R:将数据帧分为3部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆