这是一个非常简单的问题,但我似乎无法给出答案。我想创建一个匹配模式的 data frames
列表,然后 rm
这些来自全局环境。
要匹配的模式是“water_land_by_owntype_*
”
这是我尝试过的,但它不起作用......我认为 b/c 它不知道在哪里搜索字符串。
rm (matches <- list(
grep('water_land_by_owntype_*')))
-al
最佳答案
嗨,你可以这样做:
# Create some data.frame
water_land_by_owntype_1 <- mtcars
water_land_by_owntype_2 <- mtcars
water_land_by_owntype_3 <- mtcars
water_land_by_owntype_4 <- mtcars
water_land_by_owntype_5 <- mtcars
# Put them in a list
water_land_by_owntype <- lapply(ls(pattern = "water_land_by_owntype_.*"), get)
# or more directly
water_land_by_owntype <- mget(ls(pattern = "water_land_by_owntype_.*"))
# Delete them
rm(list = ls(pattern = "water_land_by_owntype_.*"))
关于r - 创建匹配模式的数据帧列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25185781/