Question

I would like to start learning how to use the xts package, but I am having a hard time loading my data.

The file is is about 6MB and it looks like this:

Date,Time,Price,Size
02/18/2014,05:06:13,49.6,200
02/18/2014,05:06:13,49.6,200
02/18/2014,05:06:13,49.6,200
02/18/2014,05:06:14,49.6,200
02/18/2014,05:06:14,49.6,193
02/18/2014,05:44:41,49.62,100
02/18/2014,06:26:36,49.52,100
02/18/2014,06:26:36,49.52,500
02/18/2014,07:09:29,49.6,100
02/18/2014,07:56:40,49.56,300
02/18/2014,07:56:40,49.55,400
02/18/2014,07:56:41,49.54,200
02/18/2014,07:56:43,49.55,100
02/18/2014,07:56:43,49.55,100
02/18/2014,07:56:50,49.55,100
02/18/2014,07:57:12,49.53,100
02/18/2014,07:57:12,49.51,2200
02/18/2014,07:57:12,49.51,100
02/18/2014,07:57:12,49.5,200

Here is the line of code I tried and the error I got:

data1<-as.xts(read.zoo("EKSO_0.txt",header = T,sep=",",format="%m/%d/%Y"))

The error I got:

Warning message:
In zoo(rval3, ix) :
some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not   unique

How can I load the "Time" column as well?

Thank you for your help.

No correct solution

OTHER TIPS

I think this is what you're looking for. It's from example 4 in the zoo vignette. You still get the warning because you still have duplicate Date, Time combos

library(zoo)
library(chron)

f <- function(d, t) as.chron(paste(as.Date(chron(d)), t))
read.zoo("EKSO_0.txt", header = TRUE, sep = ",", index.column = 1:2, FUN = f)

##                     Price Size
## (02/18/14 05:06:13) 49.60  200
## (02/18/14 05:06:13) 49.60  200
## (02/18/14 05:06:13) 49.60  200
## (02/18/14 05:06:14) 49.60  200
## (02/18/14 05:06:14) 49.60  193
## (02/18/14 05:44:41) 49.62  100
## (02/18/14 06:26:36) 49.52  100
## (02/18/14 06:26:36) 49.52  500
## (02/18/14 07:09:29) 49.60  100
## (02/18/14 07:56:40) 49.56  300
## (02/18/14 07:56:40) 49.55  400
## (02/18/14 07:56:41) 49.54  200
## (02/18/14 07:56:43) 49.55  100
## (02/18/14 07:56:43) 49.55  100
## (02/18/14 07:56:50) 49.55  100
## (02/18/14 07:57:12) 49.53  100
## (02/18/14 07:57:12) 49.51 2200
## (02/18/14 07:57:12) 49.51  100
## (02/18/14 07:57:12) 49.50  200
## Warning message:
## In zoo(rval3, ix) :
##   some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top