0

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'))
Jaap
  • 81,064
  • 34
  • 182
  • 193
anderwyang
  • 1,801
  • 4
  • 18
  • 1
    Why are you doing this? Usually it is not necessary. Why are these data.frames not together in a list, which would make this easier? – Roland Jan 18 '22 at 08:44

1 Answers1

3

You can use the usual rm(list = ls()) construct but additionally passing a pattern to ls() as the following:

rm(list = ls(pattern = "^table_*"))
Anil
  • 1,097
  • 7
  • 20