You are more or less stuck with the output you see.

The internal conversion to printed time in R (and the OS itself) is where
you are losing the microsecond precision.  R kindly buys us the subsecond
granularity over normal OS resolution, but the printing is deferred to the
OS IIRC, and you just can't be assured you see the full precision. This is
good in in many cases of course, e.g. 3 prints as 3 and not 3.00000000001
or something similar, but here it isn't what you want.

You can see the actual numbers if you really want to with:

> .index(make.index.unique(zc.xts,1e-6))
[1] 1368018124.000000 1368018127.000000 1368018127.000001 1368018127.000002
[5] 1368018127.000003 1368018133.000000
attr(,"tzone")
[1] "America/Chicago"
attr(,"tclass")
[1] "POSIXct" "POSIXt"

Note too that you are playing at the edge of floating point resolution:

> .index(make.index.unique(zc.xts,1e-7))
[1] 1368018124 1368018127 1368018127 1368018127 1368018127 1368018133
attr(,"tzone")
[1] "America/Chicago"
attr(,"tclass")
[1] "POSIXct" "POSIXt"

HTH
Jeff


On Thu, May 9, 2013 at 11:48 PM, dae <dougedmunds@gmail.com> wrote:

> 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.
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan@lemnica.com

www.lemnica.com

R/Finance 2013: Applied R in Finance
May 17, 18 Chicago, IL
www.RinFinance.com

	[[alternative HTML version deleted]]

