I have multiple data tables and all have a common column called ID
. I have a vector vec
that contains a set of ID
values.
I would like to use lapply
to subset all data tables using vec
I understand how to use lapply
to subset the data tables but my question is how to assign the subsetted results back to original data tables
Here is what I tried :
tables<-c("dt1","dt2","dt3","dt4")
lapply(mget(tables),function(x)x[ID %in% vec,])
The above gives subsets of all data tables but how do I assign them back to dt1,dt2,dt3,dt4
?