1

I am having some issues accessing the timestamp data in the IBrokers package.

Here is an example of the data I get:

                    AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.WAP AAPL.hasGaps AAPL.Count
2015-01-09 17:59:00       112    112.04   111.95        112        6043  112.011            0       2240

So when I run data[,0] I get

2015-01-09 17:59:00

The problem is that later on when I try to save that into a MySQL table I get the following error:

Error in dimnames(cd) <- list(as.character(index(x)), colnames(x)) : 
  'dimnames' applied to non-array

It looks like data[,0] does not simply contains the timestamp.

When I do a summary of the variable ts which contains data[,0] I get:

Error in `colnames<-`(`*tmp*`, value = c("ts.1", "ts.0")) : 
  'names' attribute [2] must be the same length as the vector [1]

Any tip on how to access the timestamp or convert the contents of ts to char so I can insert it into the DB will be appreciated.

EDIT:

dput() output

structure(c(112, 112.04, 111.95, 112, 6043, 112.011, 0, 2240), .Dim = c(1L, 
8L), index = structure(1420837140, tzone = "", tclass = c("POSIXct", 
"POSIXt")), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct", 
"POSIXt"), .indexTZ = "", tzone = "", .Dimnames = list(NULL, 
    c("AAPL.Open", "AAPL.High", "AAPL.Low", "AAPL.Close", "AAPL.Volume", 
    "AAPL.WAP", "AAPL.hasGaps", "AAPL.Count")), class = c("xts", 
"zoo"), from = "20150112  02:52:24", to = "20150112  02:53:24", src = "IB", updated = structure(33434342.12435, class = c("POSIXct", 
"POSIXt")))
JordanBelf
  • 3,208
  • 9
  • 47
  • 80
  • What is the structure of the original `AAPL` data? Can you run`dput()` or `str()` on it please? I have never seen `data[,0]` indexing, but it seems to return an empty matrix with the rownames - you may be better off just doing `rownames(data)` to get the timestamp. – thelatemail Jan 12 '15 at 03:32
  • Why are you subsetting by 0? You know R uses 1-based indexing, right? – Joshua Ulrich Jan 12 '15 at 03:47
  • @JoshuaUlrich That was the only way I found to access the timestamp. If I did data[,1] then I get `AAPL.Open`. But I am learning R so my approach might be wrong, it simply was the only thing that returned me the timestamp. Any tip on how to do it will be appreciated. – JordanBelf Jan 12 '15 at 03:51
  • 2
    Read the zoo and xts vignettes. – Joshua Ulrich Jan 12 '15 at 03:57
  • @JoshuaUlrich Thanks, zoo did it. time(ts) was my answer. Thanks for the tip. – JordanBelf Jan 12 '15 at 04:04
  • @JordanBelf If you find your own answer you should answer your question, that way you can contribute and help others. Or ask to JordanBelf to add an answer of his own since he mentioned where/how to find your answer :) – Jorge Campos Jan 12 '15 at 04:11

1 Answers1

2

As suggested by @JoshuaUlrich on the comments to my question, the answer was on the zoo package.

Full documentation on zoo can be found here

In my particular case by including the zoo library and simply doing:

time(data[,0])

I solve the Error in dimnames() error.

Hope it helps someone else.

JordanBelf
  • 3,208
  • 9
  • 47
  • 80