将数据框列表转换为 R 中的单个数据框 [英] Converting a list of data frames into individual data frames in R

查看:30
本文介绍了将数据框列表转换为 R 中的单个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找我认为简单的解决方案.

I have been searching high and low for what I think is an easy solution.

我有一个按因子拆分的大型数据框.

I have a large data frame that I split by factors.

eqRegions <- split(eqDataAll, eqDataAll$SeismicRegion)

现在按区域创建数据框的列表对象;总共有8个.我想遍历列表以使用另一个名称制作单个数据框.

This now creates a list object of the data frames by region; there are 8 in total. I would like to loop through the list to make individual data frames using another name.

我可以执行以下操作将列表项转换为单独的数据框,但我认为如果我有很多因素,那么有一种循环机制会很快.

I can execute the following to convert the list items to individual data frames, but I am thinking that there is a loop mechanism that is fast if I have many factors.

testRegion1 <- eqRegions[[1]]

testRegion3 <- eqRegions[[3]]

我可以手动执行上述操作并且处理得很好,但是如果我有很多区域,则效率不高.我想做的是相当于以下内容:

I can manually perform the above and it handles it nicely, but if I have many regions it's not efficient. What I would like to do is the equivalent of the following:

for (i in 1:length(eqRegions)) {
   region[i] <- as.data.frame(eqRegions[[i]])
}

我认为关键是在循环之前定义区域,但它会不断覆盖自身而不是递增.非常感谢.

I think the key is to define region before the loop, but it keep overwriting itself and not incrementing. Many thanks.

推荐答案

尝试

list2env(eqRegions,envir=.GlobalEnv)

这篇关于将数据框列表转换为 R 中的单个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆