<div>
Dear all,
</div><div><br></div>
<div><div>Suppose we've construct a data.table in this manner:</div><div><br></div><div>x <- c(1,1,1,2,2)</div><div>y <- 6:10</div><div>setattr(y, 'names', letters[1:5])</div><div>DT<- data.table(A = x, B = y)</div><div><br></div><div>DT$B</div><div><div> a b c d e </div><div> 6 7 8 9 10 </div></div><div><br></div><div>You see that DT maintains the name of vector B. But if we do:</div><div><br></div><div>DT[, names(B), by=A]</div><div><div> A V1</div><div>1: 1 a</div><div>2: 1 b</div><div>3: 1 c</div><div>4: 2 a</div><div>5: 2 b</div><div>6: 2 c</div></div><div><br></div><div>There are two things here: First, you see that only the names of the first grouping is correct (A = 1). Second, the rest of the result has the same names, and the result is also recycled to fit the length. Instead of 5 rows, we get 6 rows.</div><div><br></div><div>A way to get around it would be:</div><div><br></div><div>DT[, names(DT$B)[.I], by=A]</div><div><div> A V1</div><div>1: 1 a</div><div>2: 1 b</div><div>3: 1 c</div><div>4: 2 d</div><div>5: 2 e</div></div><div><br></div><div>However, if one wants to do:</div><div><br></div><div><div>DT[, list(list(B)), by=A]$V1</div><div>[[1]]</div><div>a b c </div><div>6 7 8 </div><div><br></div><div>[[2]]</div><div> a b </div><div> 9 10 </div></div><div><br></div><div>You see that the names are once again wrong (for A = 2). Just the first one remains right. </div><div><br></div><div>My question is, is it allowed usage of having names for column vectors? If so, then this should be a bug. If not, it'd be a great feature to have.</div><div><br></div><div>Arun</div><div><br></div></div>