[英]Adding R output in the same sheet in excel
I've been using the following functions to put my output in R in different sheets but what if I want my outputs to be below each other like my example below 我一直在使用以下函数将我的输出放在不同的工作表中,但是如果我希望我的输出彼此之间像下面的示例那样,该怎么办?
data<-loadWorkbook("trial.xls",create=TRUE)
createSheet(data,name="tr1")
writeWorksheet(data,rows,sheet="tr1")
saveWorkbook(data)
So I would want my spreadsheet to look like this 所以我希望我的电子表格看起来像这样
Values Median STD Length
3 5 6 7
6 7 7 8
Values Median STD Length
4 7 8 1
6 9 0 3
thanks guys 多谢你们
You can set starRow=
in writeWorksheet()
to set position in Excel sheet. 您可以在writeWorksheet()
设置starRow=
来设置Excel工作表中的位置。 Here is example where in one sheet I wrote data iris
and cars
. 这是我在一张纸上写数据iris
和cars
示例。 With startRow=(nrow(iris)+2)
I set position just below previous table (+2 is used as first table contains also column names that are not counted by nrow()
). 使用startRow=(nrow(iris)+2)
我将位置设置在上一个表的正下方(+2用作第一个表,其中还包含nrow()
未计数的列名)。 To remove header for the second table put header=FALSE
in second writeWorksheet()
call. 要删除第二个表的header=FALSE
在第二个writeWorksheet()
调用中添加header=FALSE
。
library(XLConnect)
data(iris)
data(cars)
wb<-loadWorkbook("trial.xls",create=TRUE)
createSheet(wb,name="tr1")
writeWorksheet(wb,iris,sheet="tr1")
writeWorksheet(wb,cars,sheet="tr1",startRow=(nrow(iris)+2),header=FALSE)
saveWorkbook(wb)
You may also want to have a look at appendWorksheet
. 您可能还想看看appendWorksheet
。 See help(appendWorksheet)
for more information. 有关更多信息,请参见help(appendWorksheet)
。
Example Code: 示例代码:
require(XLConnect) wb = loadWorkbook("test.xlsx", create = TRUE) createSheet(wb, name = "mtcars") writeWorksheet(wb, mtcars, sheet = "mtcars") for(i in 1:5) appendWorksheet(wb, mtcars, sheet = "mtcars", header = FALSE) saveWorkbook(wb)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.