I'm working through the introductory data.table
vignette where in section g) Why keep j so flexible? an example is shown that's relevant to my use case:
DT[, .(val = list(c(a,b))), by = ID]
# ID val
# 1: b 1,2,3,7,8,9
# 2: a 4, 5,10,11
# 3: c 6,12
I have a minimal working example to illustrate the problem
set.seed(1234)
size <- 10
ordering_ids <- rep(1:size, sample(1:size, replace=TRUE))
products <- letters[seq_along(ordering_ids)]
k <- data.table(o=ordering_ids, p=products)
For size <- 10
, most likely some entries result in NA
but that's not the problem. The problem is, that beyond a certain size
(around 6), I lose entries in the concatenated lists:
k
# o p
# 1: 1 a
# 2: 1 b
# 3: 2 c
# 4: 2 d
# 5: 2 e
# 6: 2 f
# 7: 2 g
# 8: 2 h
# 9: 2 i
# 10: 3 j
# 11: 3 k
# 12: 3 l
# 13: 3 m
# 14: 3 n
# 15: 3 o
# 16: 3 p
# 17: 4 q
# 18: 4 r
# [...]
Running the same command from the vignette:
k[o<=4, .(val=list(c(p))), by=o]
# o val
# 1: 1 a,b
# 2: 2 c,d,e,f,g,h,
# 3: 3 j,k,l,m,n,o,
# 4: 4 q,r,s,t,u,v,
Now, for orders o=3
, the val
list does not contain all entries (see the k
print out, it should go until r
).
What is the problem here and how could I fix it?
k[, .(val=list(c(p))), by=o]$val[4]
to verify the value. – www Dec 6 '17 at 17:08k[, toString(p), by=o]
. I brought up the issue of the list being truncated at 6 items here: github.com/Rdatatable/data.table/issues/… – Frank Dec 6 '17 at 17:45