I'm currently working in R with data.table and am trying to add a variable "data_set" to a list of data tables that holds the name of that item in the list.
For example - The list of tables is med, symp, and care and I would like to add the variable data_set to each table where in data table med, "data_set" would equal "med" and in data table symp, "data_set" would equal "symp". I know I can use lapply for this, but I'm stuck on how to store the name of each table in the "data_set" variable. I know it would go something like this....
tables<-c("med", "symp", "care")
tables_1<-lapply(mget(tables),function(x)x[, data_set:=…...])
How can I reference and store the name of each data table in the "data_set" variable?