[英]Splitting dataframe on number of rows
I want to split my dataframe based on a certain number of rows to be included in each split and then write each split out as a separate.csv file.我想根据每个拆分中包含的一定数量的行拆分我的 dataframe,然后将每个拆分写成一个单独的 .csv 文件。
library(tidyverse)
n = 10000 #number of groups
split <- correlation %>% group_by(row.names() %/% n) %>% group_walk(~ write_csv(.x, paste0("file_", .y, ".csv")))
I am using the above mentioned code to split my data, however the output.csv files lack rownames information and I would like for it to have the rownames.我正在使用上面提到的代码来拆分我的数据,但是 output.csv 文件缺少行名信息,我希望它有行名。 Can anyone please help me with this?
谁能帮我解决这个问题?
Try using write.csv instead and including row.names = TRUE as an extra argument, ie尝试改用 write.csv 并将 row.names = TRUE 作为额外参数包括在内,即
group_walk(~write.csv(.x, paste0("file_", .y, ".csv"), row.names=TRUE))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.