使用循环将列表拆分为多个数据框 [英] Use loop to split a list into multiple dataframes

查看:160
本文介绍了使用循环将列表拆分为多个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R语言的初学者,但无法在线找到针对此问题的解决方案.

I am a beginner in R and I have not been able to find a solution to this anywhere online.

我有一个由50个数据帧组成的列表对象.我想将此列表拆分为单独的data.frame对象,但是在执行此操作时遇到了麻烦.

I have a list object that is composed of 50 dataframes. I want to split this list into separate data.frame objects, but am having trouble doing this.

手动操作很简单:

a<-list[[1]]

但是我想循环它,这样我就不必手动输入所有50个组件.这不起作用:

but I want to loop it so that I don't have to manually enter all 50 components. This does not work:

for(i in 1:n.imp)
    a.i<-comb.txt1[[i]]

因为它只产生一个(最后一个)数据帧.

because it only produces a single (the last) dataframe.

有什么想法吗?

这里有一些附加的上下文:此列表是多重插补过程的产品-mi().我想将一个新变量合并到这些估算数据集中的每个数据集中,但由于该对象是一个列表,因此似乎无法弄清楚该怎么做.

Here is some additional context: This list is the product of a multiple imputation procedure -- mi(). I want to merge a new variable into each of these imputed datasets, but can't seem to figure out how to do that, since the object is a list.

推荐答案

我认为这是您追求的目标:

I think this is what you are after:

for(i in 1:length(comb.txt1)) {
    assign(paste0("a.", i), comb.txt1[[i]])
}

这篇关于使用循环将列表拆分为多个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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