-1

I have a result and wants to save it into files for comparisons with other statistical tools. But I keep getting this error. I really do need assistance please. Thanks.

Error in write_xlsx(nwc_cost, "result_nwc.xlsx") : Argument x must be a data frame or list of data frames

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Spencer
  • 23
  • 5
  • 1
    What does `nwc_cost` look like? Is it a data.frame? If not, you would need to shape it into on, or be more clear just exactly what you want this Excel file to look like. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 28 '20 at 21:32

2 Answers2

2

If nwc_cost is a data.frame, you could use the openxlsx package with the following code:

library(openxlsx)
wb <- createWorkbook("workbook")
addWorksheet(wb, sheetName = "data")
# add your data
writeData(wb, "data", nwc_cost, startCol = 1, startRow = 1)
# then save workbook
saveWorkbook(wb, file = "myexcelfile.xlsx", overwrite = FALSE)

You can specify the path in argument file of saveWorkbook. It usually runs very well with all systems.

Raphaele Adjerad
  • 1,117
  • 6
  • 12
0

This answer depends on the structure of your data:

write_xlsx(as.data.frame(do.call("rbind", nwc_cost)), "result_nwc.xlsx")
hello_friend
  • 5,682
  • 1
  • 11
  • 15