Dear all, Suppose we've construct a data.table in this manner:
x <- c(1,1,1,2,2) y <- 6:10 setattr(y, 'names', letters[1:5]) DT<- data.table(A = x, B = y) DT$B a b c d e 6 7 8 9 10 You see that DT maintains the name of vector B. But if we do: DT[, names(B), by=A] A V1 1: 1 a 2: 1 b 3: 1 c 4: 2 a 5: 2 b 6: 2 c 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. A way to get around it would be: DT[, names(DT$B)[.I], by=A] A V1 1: 1 a 2: 1 b 3: 1 c 4: 2 d 5: 2 e However, if one wants to do: DT[, list(list(B)), by=A]$V1 [[1]] a b c 6 7 8 [[2]] a b 9 10 You see that the names are once again wrong (for A = 2). Just the first one remains right. 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. Arun
_______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
