<div dir="ltr"><div class="gmail_extra">I get similar timings to arun, with the data.table call being a lot slower than the other timings. If data.table is not optimized for that .SD expression, perhaps that is okay because, as Arun pointed out, there are alternatives.. I can't guess why it would perform differently on different hardware, though...</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"># alternatives:</div><div class="gmail_extra"><div class="gmail_extra"><font face="courier new, monospace">a <- dt1[dt1[, .I[.N], by='Date']$V1]</font></div>
<div class="gmail_extra"><font face="courier new, monospace">b <- dt1[J(unique(Date)),,mult='last'] # a little slower</font></div><div class="gmail_extra"><font face="courier new, monospace">d <- dt1[, .SD[.N], by='Date'] # 600x slower; it would take ages to benchmark</font></div>
<div class="gmail_extra"><font face="courier new, monospace">identical(a,b) # true</font></div><div class="gmail_extra"><font face="courier new, monospace">identical(a,d) # false</font></div><div class="gmail_extra"><font face="courier new, monospace">identical(as.data.frame(d),as.data.frame(a)) # true</font></div>
<div class="gmail_extra"><font face="courier new, monospace"><br></font></div><div class="gmail_extra"><font face="courier new, monospace">--Frank</font></div><div><br></div></div></div>