1

I have a bunch of data frames whose names are "yob.14", ..., "yob.60", based on year of birth. How do I delete them without having to rm() each one separately? I tried

rm(paste0("yob.",i))

but that got me an error message:

... must contain names or character strings"

4

1 回答 1

3

用这个:

rm(list=paste0("yob.",14:60))

编辑:使用@baptiste 的建议:

rm(list=Filter(exists, paste0("yob.", 14:60)))

如果生成的某些名称不引用现有数据框。

另一种选择,使用正则表达式(感谢@mnel):

rm(list=ls(pattern="^yob\\."))
于 2013-09-06T00:49:45.997 回答