创建匹配模式的数据帧列表 [英] create list of dataframes matching a pattern
本文介绍了创建匹配模式的数据帧列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个非常简单的问题,但我似乎无法给出答案.我想创建一个匹配模式的 data frames
列表,然后 rm
这些来自全局环境.
This is a very simple question, however I can't seem to come up w/ an answer. I would like to create a list of data frames
matching a pattern, then rm
these from the global environment.
要匹配的模式是'water_land_by_owntype_*
'
这是我尝试过的,但它不起作用......我认为 b/c 它不知道在哪里搜索字符串.
This is what I have tried, but it doesn't work...I think b/c it doesn't know where to search for the string.
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_.*"))
这篇关于创建匹配模式的数据帧列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文