Exporting a Zoo to existing xls file

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Exporting a Zoo to existing xls file

vincent.deluard
This post has NOT been accepted by the mailing list yet.

Hi R users,

I am trying to export a zoo object (x, defined below) into an exisitng .xls spreadsheet:

x.date <- as.POSIXct(paste("2003-", rep(1:4, 4:1), "-", sample(1:28, 10, replace = TRUE), sep = ""))
x <- zoo(matrix(rnorm(24), ncol = 2), x.date)

Specifically, I would like this data to go into cells A1 to C12 of an existing spreadsheet called 'myTest.xls'

From looking at the doc, it seems that the RODBC package deals with this issue.

I have tried the following:

> odbcCloseAll()
> library(RODBC)
> xlsFile <- odbcConnectExcel("myTest.xls", readOnly = FALSE)
> sqlSave(xlsFile,x,tablename=NULL,append = TRUE)

But I get the following error message:
Error in sqlSave(xlsFile, x, tablename = NULL, append = TRUE) :
  should be a data frame

Is it possible to save a Zoo in an existing xls file using this method?
If so, my secondary question would be how to specify a given (existing) sheet and placement ('Sheet1',cells A1 to G12 for example) to send my Zoo object.

I very much appreciate the help!!!

Vincent.