如何在R

时间:2017-12-21 14:22:02

标签: r excel loops

我确实需要将每个循环结果保存在EXCEL文件中,我的代码如下:

library(xlsx)
library(bootstrap)
rawData <- read.xlsx("C:\\Users\\Taqwa\\Downloads\\9660.xlsx",1)
#load<-function(AveLd,AveOff,AveOn,DWELL_SEC)
#  + + sum((AveLd-AveOff)+AveOn)
#bootstrap(rawData,10000,load())
three_d_array <- array(0,dim = c(270, 6, 20))
for (i in 1:20){
  candy = 1:nrow(rawData)
  B=sample(candy,nrow(rawData) , replace=T)
  a=rawData[B,]
  three_d_array[,,i]=as.matrix(a)
}

赞赏你的帮助

1 个答案:

答案 0 :(得分:0)

在你的循环之前

,放:

out <- createWorkbook()

循环内部:

assign(paste0("sheet", i), createSheet(wb = out, sheetName = as.character(i)))
# you don't really need your three_d_array
addDataFrame(x = a, sheet = eval(as.name(paste0("sheet", i))))
循环后

saveWorkbook(out, "[your path]/[file name].xlsx")