Rohit Saluja
Rohit Saluja

Reputation: 1517

Concatenate all values of field in Data.Table R

I am trying to collapse the value of field Value_From of below data set using below expression

dt [ , unique(Value_From) , by = c("From_Type","To_Type") ][ , .(val = list(c(V1)) , `Unique_From_IDs` = .N ) , by = c("From_Type","To_Type")]

enter image description here

However when I run this some of the values are getting dropped and I am getting below results

enter image description here

Please help me understand why some of the ID's are getting dropped.

Appreciate the help!

Upvotes: 0

Views: 42

Answers (1)

C-x C-c
C-x C-c

Reputation: 1311

Additionally, to the comments above, try:

dt [ , unique(Value_From) , by = c("From_Type","To_Type") ][ , .(val = list(list(V1)) , `Unique_From_IDs` = .N ) , by = c("From_Type","To_Type")]

The double list() call will make your table look like:

... ... listCol
... ... <list>

This way you won't encounter the somewhat confusing problem of abbreviation.

Upvotes: 1

Related Questions