公式“Meldingen”中的引号将无济于事。您可以尝试这样的事情(以 iris 数据集为例)。要了解该过程,请准备一个名为“COVID19”的 .xlsx 文件,其中包含一张“Meldingen”表,其中包含 10 行随机数据(从 A1 开始)和您想要的列数(无标题)。虹膜数据集最后一列的前 10 行将被添加到文件中(在第一个空列中)。
# Open the source .xlsx file (the receiver of the data)
source=read.xlsx("COVID19.xlsx","Meldingen",header = FALSE)
# Get the last computed column of the df which has to be added to the .xlsx file
data=as.data.frame(iris[1:10,ncol(iris)])
# Create the workbook and the sheet (even if they already exist)
wb = createWorkbook()
sheet = createSheet(wb, "Meldingen")
# Get information about the existing sheet (the first empty column)
i=dim(source)[2]+1
# Add the data from the source .xlsx file
addDataFrame(source, sheet=sheet, row.names=FALSE, col.names =FALSE, startRow = 1)
# Add the data from the R df
addDataFrame(data, sheet=sheet, row.names=FALSE, col.names =FALSE, startRow = 1, startColumn = i)
# Overwrite the existing file
saveWorkbook(wb, "COVID19.xlsx")
将 data=as.data.frame(iris[1:10,ncol(iris)]) 替换为 data=as.data.frame(Meldingen[,ncol(iris)]) 假设“Meldingen”是 R 中数据框的名称。