简体   繁体   中英

R: split dataframe into 3 parts

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)

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

Am I missing anything?

我们可以在rep使用length.out参数

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM