【发布时间】:2017-01-24 01:35:02
【问题描述】:
我正在尝试将一个函数应用于我在 R 中的全局环境中的所有类似拼写的数据帧。我想将此函数应用于所有这些数据帧,但如果没有我指定,我不知道该怎么做1 x 1。我想将数据框以与以前相同的拼写返回到全局环境。
mtcars_test = mtcars
iris_test = iris
#....etc......could be 2 of them or 88 of them...but they will all end in "_test"
# figure out what data frames I am working with
list_of_my_dfs = lapply(ls(pattern = "*_test"), get)
#my function just multiples everything by 2
mytest_function = function(df){ df = df*2; return(df)}
helpme_return_these_dfs_to_outside_the_list=plyr::llply(list_of_my_dfs, mytest_function)
这是我需要帮助的地方。我想将我的函数应用于列表中的每个数据框,然后将该列表中的数据框“返回”到我的环境中。因此mtcars_test 和所有其他数据帧将在任何地方乘以 2 并返回到全局环境。
【问题讨论】:
-
为什么不把所有东西都放在一个列表中呢?
-
我可以将它保存在一个列表中,但我现在的目的是我需要将它们提取出来。我已经知道如何做到这一点,并且认为我现在正在这样做。
-
“答案”可能是
list2env,但请不要为此烦恼。只需将它们列在一个列表中即可。