It is definitely as.POSIXct (but in conjunction with data.table?) that causes problems, as replacing it by as.Date, in the previous lines of code, leads to correct result.<br>Cheers<div><br><div class="gmail_quote">2013/1/18 statquant <span dir="ltr"><<a href="mailto:statquant@outlook.com" target="_blank">statquant@outlook.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello I might have found a bug.<div>I really cannot explain the following (please be indulgent as I narrowed the most I could).</div>
<div><br></div><div><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">library(data.table)</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">DT = data.table(X=as.POSIXct( c(rep("15DEC2008:00:00:00",10)</span><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">,"15DEC2008:00:00:00",rep("</span><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">17DEC2008:00:00:00",2)),</span><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">format="%d%b%Y:%H:%M:%S"),Y=c(</span><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">1534,61,74,518,519,1519,1520,</span><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">1524,3127,29250,30609,43,7853)</span><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">)</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">setkey(DT,X,Y)</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><br></span></div><div><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">#Here is what I see after the sort </span></div>
<div><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><br></span></div><div><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">DT</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> X Y</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 1: 2008-12-15 </span><span style="font-size:13.333333969116211px;font-family:arial,sans-serif"><font color="#ff0000"><b>1534</b></font></span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 2: 2008-12-15 61</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 3: 2008-12-15 74</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 4: 2008-12-15 518</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 5: 2008-12-15 519</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 6: 2008-12-15 1519</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 7: 2008-12-15 1520</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 8: 2008-12-15 1524</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 9: 2008-12-15 3127</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">10: 2008-12-15 29250</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">11: 2008-12-15 30609</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">12: 2008-12-17 43</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">13: 2008-12-17 7853</span></div><div><br></div><div>#I thought that it was a POSIXct problem but if I can get the correct answer like this:</div>
<div><br></div><div><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">DT[order(X,Y),]</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> X Y</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 1: 2008-12-15 61</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 2: 2008-12-15 62</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 3: 2008-12-15 74</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 4: 2008-12-15 518</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 5: 2008-12-15 519</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 6: 2008-12-15 1519</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 7: 2008-12-15 1520</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 8: 2008-12-15 1524</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> 9: 2008-12-15 3127</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">10: 2008-12-15 29250</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">11: 2008-12-15 30609</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">12: 2008-12-17 43</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">13: 2008-12-17 7853</span></div><div><br></div><div>#Here is my session (just launched it)<br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><br></span></div><div><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">R> sessionInfo()</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">R version 2.15.2 (2012-10-26)</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">Platform: x86_64-pc-linux-gnu (64-bit)</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">locale:</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=C </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> [4] LC_COLLATE=en_GB.UTF-8 LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=en_GB.UTF-8 </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"> [7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">[10] LC_TELEPHONE=C LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">attached base packages:</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">[1] stats graphics grDevices datasets utils methods base </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">other attached packages:</span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">[1] data.table_1.8.7 inline_0.3.10 Rcpp_0.10.2 vimcom_0.9-5 setwidth_1.0-2 </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">[6] colorout_0.9-9 </span><br style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif">
<span style="color:rgb(34,34,34);font-size:13.333333969116211px;font-family:arial,sans-serif"><br></span></div><div><br></div>
</blockquote></div><br></div>