How to append different R outputs into one excel spreadsheet [duplicate]

百般思念 提交于 2019-12-24 13:52:46

问题


So whenever I want to run my code seperately for different datasets...I want the output from my code to be saved in the same excel spreadsheet but at different sheets....So If I run my code for 20 different datasets...I would want all the output to saved in the same excel spreadsheet but different worksheets...so I would have 20 worksheets in a single excel spreadsheet...is there a special function in r that would let me do this?.....so lets say my existing spreadsheet is called 'Values.csv'....How would I append the rest of my output to this same spreadsheet.

I usually just use write.csv(data,'Values.csv') etc....But I'm not sure how to append my output to this same worksheet...


回答1:


You can use library XLConnect to do this.

library(XLConnect)

#some sample data
your.data=data.frame(a=1:10,b=21:30)

#Create .xls file
wb <- loadWorkbook("newfile.xls", create = TRUE)

#Create Sheet in file
createSheet(wb,name="name_one")

#write data
writeWorksheet(wb,your.data,sheet="name_one")

#save .xls file
saveWorkbook(wb)


来源:https://stackoverflow.com/questions/15676104/how-to-append-different-r-outputs-into-one-excel-spreadsheet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!