Yes, correct behaviour. That's an ad hoc by which preserves the group
order (the order of first appearance of each group). From ?data.table,
the second part of this sentence :
"The order of the rows within each group is preserved, as is the order
of the groups."
That was new in 1.6.3 :
o Ad hoc grouping now returns results in the same order each
group first appears in the table, rather than sorting the
groups. Thanks to Steve Lianoglou for highlighting. The order
of the rows within each group always has and always will be
preserved. For larger datasets a 'keyed by' is still faster;
e.g., by=key(DT).
To reorder the ad hoc by result, change 'by=' to 'keyby=' (in v1.8.0).
Not be confused with keyed by!
Matthew
On Tue, 2012-04-10 at 19:51 -0400, Joseph Voelkel wrote:
> Here is a simple example of a simple question:
>
>
>
> dt<-data.table(a=rep(1:5,1:5),b=1,c=rep(1:3,5))
>
> dt
>
> dt[,seq_along(b),by=a] # expected behavior (note: dt is already in
> order of a)
>
> setkey(dt,c) # to sort by c
>
> dt
>
> dt[,seq_along(b),by=a] # expected behavior? Appears to be in order of
> unique(dt$a)
>
>
>
> Thanks,
>
>
>
> Joe Voelkel
>
>
> _______________________________________________
> datatable-help mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help