如何在R中单独保存列表的元素? [英] How to save the elements of a list individually in R?
本文介绍了如何在R中单独保存列表的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个很长的元素列表,我想将每个元素分别保存为一个数据框.是的,现在我正尝试通过以下方式做到这一点:
So I've got a pretty long list of elements, and I want to save each of these elements individually as a dataframe. Right, now I'm trying to do so by:
for (i in 1:length(mylist)) {
save.dta13(mylist[i], file=paste0(names(mylist)[i], ".dta"))
}
但这似乎没有用,有什么主意吗?
But that doesn't seem to be working, any ideas?
推荐答案
我们可以使用lapply
遍历list
lapply(names(mylist), function(nm)
save.dta13(mylist[[nm]], paste0(nm, ".dta")))
这篇关于如何在R中单独保存列表的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文