[datatable-help] Unintuitive behavior with by=
Matthew Dowle
mdowle at mdowle.plus.com
Sun Nov 13 03:22:28 CET 2011
Grouping variables are length 1. Background in FAQ 2.10.
.N can be used instead of length().
On Sat, 2011-11-12 at 12:08 -0800, Muhammad Waliji wrote:
> I sometimes want to check the number of rows for each value of a
> variable. I use the following method. The first syntax doesn't work,
> but the second does. I think that they ought to give the same result.
>
>
> > DT <- data.table(x=rep(c(1, 2), each=10), y=1:20)
> > DT[, length(x), list(x)]
> x V1
> [1,] 1 1
> [2,] 2 1
> > DT[, length(y), list(x)]
> x V1
> [1,] 1 10
> [2,] 2 10
>
>
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
More information about the datatable-help
mailing list