I have a data table, as shown below.
dt <- data.table(label = c("a", "b", "c", "d", "e"),value = c(list(1),list(2),list(3),list(4),list(5)))
The "value" column is a list column, and currently, each element (which is also a list) in this column doesn't have any names. I want to use the
set_names function (or any other similar function) to assign names to these lists in the "value" column.
However, when I tried using the following code, it didn't work.
dt[, value := set_names(value, label)]
I tried to use:
It didn't change the names of the "value" column within the
dt data table.
I also tried :
setattr(dt$value, 'names', 'dt$label')
which solved the previous problem, but now I have another issue: if there are other columns that are created using the "value" column, such as dt[, value2 := map(value, as.character)], these other columns are unable to retain the names of the lists in the "value" column.
So the question is : how to set the names for each list in the list column within the data table.