<div>
                    <div>Sorry, but I'm not sure what your question is here. There seems to be different timings between you and Steve. You want to get it verified as to which one is true? On my system, Steve's takes 0.003 seconds. </div><div><br></div><div>However, a *faster* version than Steve's solution (on bigger data) would be:</div><div><br></div><div>    x[x[, .I[.N], by='Date']$V1]</div>
                </div>
                <div><div><br></div><div>Arun</div><div><br></div></div>
                 
                <p style="color: #A0A0A8;">On Friday, August 16, 2013 at 6:52 AM, arun wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div><div>HI,</div><div>This is a follow up from a post in R-help mailing list. (<a href="http://r.789695.n4.nabble.com/How-to-extract-last-value-in-each-group-td4673787.html">http://r.789695.n4.nabble.com/How-to-extract-last-value-in-each-group-td4673787.html</a>).  </div><div><br></div><div><br></div><div>In short, I tried the below using data.table(), but found to be slower than some of the other methods.  Steve Lianoglou also tried the same and got it much faster (system.time()~ 0.070  vs. ~40 ).</div><div><br></div><div>###data</div><div><br></div><div>dat1<- structure(list(Date = c("06/01/2010", "06/01/2010", "06/01/2010", </div><div>"06/01/2010", "06/02/2010", "06/02/2010", "06/02/2010", "06/02/2010", </div><div>"06/02/2010", "06/02/2010", "06/02/2010"), Time = c(1358L, 1359L, </div><div>1400L, 1700L, 331L, 332L, 334L, 335L, 336L, 337L, 338L), O = c(136.4, </div><div>136.4, 136.45, 136.55, 136.55, 136.7, 136.75, 136.8, 136.8, 136.75, </div><div>136.8), H = c(136.4, 136.5, 136.55, 136.55, 136.7, 136.7, 136.75, </div><div>136.8, 136.8, 136.8, 136.8), L = c(136.35, 136.35, 136.35, 136.55, </div><div>136.5, 136.65, 136.75, 136.8, 136.8, 136.75, 136.8), C = c(136.35, </div><div>136.5, 136.4, 136.55, 136.7, 136.65, 136.75, 136.8, 136.8, 136.8, </div><div>136.8), U = c(2L, 9L, 8L, 1L, 36L, 3L, 1L, 4L, 8L, 1L, 3L), D = c(12L, </div><div>6L, 7L, 0L, 6L, 1L, 0L, 0L, 0L, 2L, 0L)), .Names = c("Date", </div><div>"Time", "O", "H", "L", "C", "U", "D"), class = "data.frame", row.names = c(NA, </div><div>-11L))</div><div><br></div><div><br></div><div>indx<- rep(1:nrow(dat1),1e5)</div><div>dat2<- dat1[indx,]</div><div>dat2[-c(1:11),1]<-format(rep(seq(as.Date("1080-01-01"),by=1,length.out=99999),each=11),"%m/%d/%Y")</div><div> dat2<- dat2[order(dat2[,1],dat2[,2]),]</div><div>row.names(dat2)<-1:nrow(dat2)</div><div><br></div><div><br></div><div><br></div><div>#Some speed comparisons (more in the link):</div><div>system.time(res1<-dat2[c(diff(as.numeric(as.factor(dat2$Date))),1)>0,])</div><div>#   user  system elapsed </div><div> # 0.528   0.012   0.540 </div><div> system.time(res7<- dat2[cumsum(rle(dat2[,1])$lengths),])</div><div>#   user  system elapsed </div><div> # 0.156   0.000   0.155 </div><div><br></div><div><br></div><div>library(data.table)</div><div>system.time({</div><div>dt1 <- data.table(dat2, key=c('Date', 'Time'))</div><div> ans <- dt1[, .SD[.N], by='Date']})</div><div><br></div><div> # user  system elapsed </div><div> #39.860   0.020  39.952   #############slower than many other methods</div><div>ans1<- as.data.frame(ans)</div><div> row.names(ans1)<- row.names(res7)</div><div> attr(ans1,"row.names")<- attr(res7,"row.names")</div><div> identical(ans1,res7)</div><div>#[1] TRUE</div><div><br></div><div><br></div><div><br></div><div><br></div><div>Steve Lianoglou reply is below:</div><div>############################</div><div><br></div><div><br></div><div>Amazing. This is what I get on my MacBook Pro, i7 @ 3GHz (very close</div><div>specs to your machine):</div><div><br></div><div>R> dt1 <- data.table(dat2, key=c('Date', 'Time'))</div><div>R> system.time(ans <- dt1[, .SD[.N], by='Date'])</div><div>   user  system elapsed</div><div>  0.064   0.009   0.073  ###########################</div><div><br></div><div>R> system.time(res7<- dat2[cumsum(rle(dat2[,1])$lengths),])</div><div>   user  system elapsed</div><div>  0.148   0.016   0.165</div><div><br></div><div>On one of our compute server running who knows what processor on some</div><div>version of linux, but shouldn't really matter as we're talking</div><div>relative time to each other here:</div><div><br></div><div>R> system.time(ans <- dt1[, .SD[.N], by='Date'])</div><div>   user  system elapsed</div><div>  0.160   0.012   0.170</div><div><br></div><div>R> system.time(res7<- dat2[cumsum(rle(dat2[,1])$lengths),])</div><div>   user  system elapsed</div><div>  0.292   0.004   0.294</div><div>##############################################</div><div><br></div><div>My sessionInfo#######</div><div>sessionInfo()</div><div>R version 3.0.1 (2013-05-16)</div><div>Platform: x86_64-unknown-linux-gnu (64-bit)  (linux mint 15)</div><div><br></div><div>locale:</div><div> [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              </div><div> [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    </div><div> [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   </div><div> [7] LC_PAPER=C                 LC_NAME=C                 </div><div> [9] LC_ADDRESS=C               LC_TELEPHONE=C            </div><div>[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       </div><div><br></div><div>attached base packages:</div><div>[1] stats     graphics  grDevices utils     datasets  methods   base     </div><div><br></div><div>other attached packages:</div><div>[1] data.table_1.8.8 stringr_0.6.2    reshape2_1.2.2  </div><div><br></div><div>loaded via a namespace (and not attached):</div><div>[1] plyr_1.8    tools_3.0.1</div><div><br></div><div>CPU ####################</div><div>I use Dell XPS L502X</div><div> * Processor 2nd Gen Core i7 Intel i7-2630QM / 2 GHz ( 2.9 GHz ) ( Quad-Core ) </div><div> * Memory 6 GB / 8 GB (max) </div><div> * Hard Drive 640 GB - Serial ATA-300 - 7200 rpm  </div><div><br></div><div>Any help will be appreciated.</div><div>Thanks.</div><div>A.K.</div><div>_______________________________________________</div><div>datatable-help mailing list</div><div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>