【问题标题】:Using for loop to create series xlsx files in R使用 for 循环在 R 中创建系列 xlsx 文件
【发布时间】:2018-12-12 09:00:04
【问题描述】:

我有一个数据集,想通过一个变量将其拆分为系列 xlsx 文件:“块”。 我可以编写将单个块导出到一个文件中的代码,但我需要一次创建它们。 我目前的代码是:

data_block1<-subset(data_name, Block %in% c(1))
data_block1$Detail<-data_Mf$Detail
write.xlsx(data_block1, "C:/block1.xlsx")

如何将这些脚本转移到 for 循环中?谢谢。

【问题讨论】:

    标签: r excel for-loop


    【解决方案1】:

    如果没有提供可重现的代码,并且根据您提供的内容,您可以执行以下操作:

    for(i_block in Block) {
      tmp_df <- subset(data_name, Block %in% i_block)
      # tmp_df$Detail<-data_Mf$Detail     # why is this here and what does it do?
      write.xlsx(tmp_df, paste0("C:/block", i_block, ".xlsx"))
    }
    

    【讨论】:

    • tmp_df$Detail
    猜你喜欢
    • 2016-11-21
    • 2018-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2013-09-09
    • 2020-07-16
    • 2014-03-31
    相关资源
    最近更新 更多