Write data into a specific workbook sheet

前端 未结 3 1717
温柔的废话
温柔的废话 2021-01-15 05:38

I have a data frame e.g.

a=1:10 
b=31:40
c=data.frame(a=a,b=b)

and I will need to write this data frame into a specific Excel sheet (\"Shee

3条回答
  •  借酒劲吻你
    2021-01-15 06:11

    This will add a new named sheet to an existing Excel workbook without altering existing sheets:

    # create data in R
    a = 1:10 
    b = 31:40
    c0 = data.frame(a=a,b=b)
    
    #  write data object 'c0' to existing Excel file 
    # 'Book1.xlsx' into a new sheet called 'Sheet1'
    library(XLConnect)
    writeWorksheetToFile(file = "C:/.../Book1.xlsx", data = c0, sheet = "Sheet1")
    

    Note that if the workbook already has a Sheet1 then this function would silently overwrite it. So you'll need to make sure your sheet names are unique.

提交回复
热议问题