I can not add a list column to a data.table with one row:
library(data.table)
dt = data.table(a = 1)
list_column = list(list(a = 1, b = 2))
# does not work:
dt$b = list_column
Error in set(x, j = name, value = value) :
Supplied 2 items to be assigned to 1 items of column 'b'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.
Error in `[.data.table`(dt, , `:=`(b, list_column)) :
Supplied 2 items to be assigned to 1 items of column 'b'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.
The following workaround works and prodcues the desired result.
dtb = data.table(b = list_column)
cbind(dt, dtb)
a b
<num> <list>
1: 1 <list>
I can not add a list column to a data.table with one row:
The following workaround works and prodcues the desired result.