I want to use a list as a simple dictionary to change values when the lookup to the list is not null. I'd expected this to work, but it doesn't;
assoc_values <- list("A" = "GROUP1", "C" = "GROUP1", "B" = "GROUP2", "D" = "GROUP3")
some_data_table[!is.null(assoc_values[[lookup_column]]), "mapped_col" := assoc_values[[lookup_column]]]
It fails with error msg Error: recursive indexing failed at level 2
. I've tried other approaches like ifelse(!is.null(assoc_values[[lookup_column]]), ...)
but always fails.
below there is a reproducible example:
library(data.table)
assoc_values <- list("A" = "GROUP1", "C" = "GROUP1", "B" = "GROUP2", "D" = "GROUP2")
some_data_table <- data.table('col1' = seq(1, 10), 'lookup_column' = c('A', 'A', 'E', 'B', 'D', 'C', 'A', 'F', 'C', 'T'))
some_data_table[!is.null(assoc_values[[lookup_column]]), "mapped_col" := assoc_values[[lookup_column]]]