无法将R数据框追加到现有Excel中而不进行覆盖 [英] Unable to Append R data frame into existing Excel without overwriting

查看:248
本文介绍了无法将R数据框追加到现有Excel中而不进行覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者,正在尝试将RStudio中的R数据框简单地插入到现有Excel工作表中,而不会丢失该工作表中的先前数据或覆盖整个文件。在第16行第1列的工作表 August的 Reporting.xlsx文件中插入新的数据帧(15行,4列),以便不会丢失先前的信息?

I am a beginner and am trying to simply insert an R data frame from RStudio into an existing Excel sheet without losing previous data in that sheet or overwriting the whole file, eg. insert new data frame (15 rows, 4 columns) in file "Reporting.xlsx" in Sheet "August" from row 16, column 1, so that the previous info is not lost ?

谢谢!

推荐答案

类似这样的东西:

library(openxlsx)
library(dplyr)

# Get existing data and append new data
dat = readWorkbook("Reporting.xlsx", sheet="August")
dat = bind_rows(dat, new_data_frame)

# Write updated data frame to existing worksheet
wb = loadWorkbook("Reporting.xlsx")
writeData(wb, "August", dat)

# Save file (with new name for testing purposes)
saveWorkbook(wb, "Reporting_test.xlsx")

# To overwrite the pre-existing data file, you can do the following (commented out for safety)
#saveWorkbook(wb, "Reporting.xlsx", overwrite=TRUE)

这篇关于无法将R数据框追加到现有Excel中而不进行覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆