R:将列表打印到文本文件 [英] R: Print list to a text file

查看:71
本文介绍了R:将列表打印到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R中有一个这样的列表:

I have in R a list like this:

> print(head(mylist,2))
[[1]]
[1] 234984  10354  41175 932711 426928

[[2]]
[1] 1693237   13462

列表中的每个元素具有不同数量的元素.

Each element of the list has different number of its elements.

我想将此列表打印到这样的文本文件中:

I would like to print this list to a text file like this:

mylist.txt
234984  10354  41175 932711 426928
1693237   13462

我知道我可以使用sink(),但是它会打印元素[[x]],[y]的名称,因此我想避免使用它.另外,由于列表中每个元素的元素数量不同,因此无法使用write()或write.table().

I know that I can use sink(), but it prints names of elements [[x]], [y] and I want to avoid it. Also because of different number of elements in each element of the list it is not possible to use write() or write.table().

推荐答案

未经测试,但应该有效(注释后编辑)

Not tested, but it should work (edited after comments)

lapply(mylist, write, "test.txt", append=TRUE, ncolumns=1000)

这篇关于R:将列表打印到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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