How to drop object accoring the object's name [duplicate]
There are data.frame in R , I want to drop all of them whice name like 'table_*'.
rm(c('table_a','table_j','table_w','table_z'))
seems can't work. Anyone can help ? Thanks
table_a <- data.frame(cat='a')
table_j <- data.frame(cat='b')
table_w <- data.frame(cat='c')
table_z <- data.frame(cat='d')
mapping_a <- data.frame(cat='d')
mapping_b <- data.frame(cat='d')
rm(c('table_a','table_j','table_w','table_z'))
Solution 1:
You can use the usual rm(list = ls())
construct but additionally passing a pattern
to ls()
as the following:
rm(list = ls(pattern = "^table_*"))