[R-SIG-Finance] convert ordered but non-unique csv to unique xts

dae dougedmunds at gmail.com
Fri May 10 06:48:18 CEST 2013


I placed the example code in a file named "zc.csv"

 Time,High,Low,Open,Close,Vol 
 2013/05/08 08:02:04,6.35,6.345,6.35,6.345,172 
 2013/05/08 08:02:07,6.345,6.3425,6.345,6.3425,69 
 2013/05/08 08:02:07,6.3425,6.34,6.3425,6.34,74 
 2013/05/08 08:02:07,6.3425,6.34,6.34,6.3425,80 
 2013/05/08 08:02:07,6.345,6.3425,6.3425,6.345,87 
 2013/05/08 08:02:13,6.345,6.3425,6.345,6.3425,110 

I  ran these steps to convert to xts and make the index unique:
-------
library("quantmod")
ds = options(digits.secs=6)
x = "zc.csv"
zc.xts =  as.xts(read.zoo(x, header = T, sep = ",", format = "%Y/%m/%d
%H:%M:%S", tz=""))
# that code works, but generates a warning:
#Warning message:
#  In zoo(rval3, ix) :
#  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique

zc2.xts = make.index.unique (zc.xts)
isOrdered( .index(zc2.xts) )  #evaluates to TRUE
zc2.xts

---------------
This is how zc2.xts appears: 

                                                      High    Low     Open  
Close   Vol
2013-05-08 08:02:04.000000 6.3500 6.3450 6.3500 6.3450 172
2013-05-08 08:02:07.000000 6.3450 6.3425 6.3450 6.3425  69
2013-05-08 08:02:07.000000 6.3425 6.3400 6.3425 6.3400  74
2013-05-08 08:02:07.000001 6.3425 6.3400 6.3400 6.3425  80
2013-05-08 08:02:07.000002 6.3450 6.3425 6.3425 6.3450  87
2013-05-08 08:02:13.000000 6.3450 6.3425 6.3450 6.3425 110

Look at the index of the second and third records.  
Although apparently the indexes are unique, the indexes look the same.
Is there some way to make them look different?


I am running this code on a 32 bit WinXP SP3 box.
I am looking at it through RStudio 0.97.449




--
View this message in context: http://r.789695.n4.nabble.com/convert-ordered-but-non-unique-csv-to-unique-xts-tp4666712p4666735.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list