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.<div><br></div>
<div><div>> DT <- data.table(x=rep(c(1, 2), each=10), y=1:20)</div></div><div><div>> DT[, length(x), list(x)]</div><div> x V1</div><div>[1,] 1 1</div><div>[2,] 2 1</div><div>> DT[, length(y), list(x)]</div>
<div> x V1</div><div>[1,] 1 10</div><div>[2,] 2 10</div></div><div><br></div>