我有一个列表的列表存储在一个包含864项的变量中,它看起来像这样。
- 〉所有权限全局
[[1]]
[[1]][[1]]
[1] "Agent is selling "
[[1]][[2]]
[1] "Yes, if asked to subscribe "
[[1]][[3]]
[1] "Yes, if offered the two-year option "
[[1]][[4]]
[1] "No, Agent should offer"
[[1]][[5]]
[1] "No, it is never ethical"
.
.
.
.
.
[[864]]
[[864]][[1]]
[1] "Agent is selling "
[[864]][[2]]
[1] "Yes, if asked to subscribe"
[[864]][[3]]
[1] "Yes, if offered the two-year "
[[864]][[4]]
[1] "No, Agent should offer "
[[864]][[5]]
[1] "No, it is never ethical
- 我需要将中的输出存储在包含2列的csv文件中**.第1列将方括号替换为词干和4个选项,如下例所示&第2列应包含所有864个项目的相应值&所有864个项目应如下所示
'Stem',"Agent is selling subscriptions "
"Option 1",
"Yes, if asked to subscribe"
"Option 2",
"Yes, if offered the two-year option "
"Option 3",
"No, Agent should offer "
"Option 4",
"No, it is never ethical
我该如何实现这一目标?
做dput(head(yourlist))可以得到-
list(list("Agent is selling subscriptions ",
"Yes, if offered the two-year option",
"Yes, if asked to subscribe ",
"No, Agent should offer ",
"No, it is never ethical"),
list("Agent is selling subscriptions",
"Yes, if offered the two-year option",
"Yes, if asked to subscribe ",
"No, it is never ethical ",
"No, Agent should offer "))
3条答案
按热度按时间ggazkfy81#
下面是一个小例子:
然后你可以使用
write.csv()
将y
导出到CSV。不确定你想如何将y
作为数据框 * 并且 * 仍然可以像你展示的那样打印它。也许你只是想让它成为一个命名列表?也许这会让你更接近你想要的输出:根据项目的大小,您还可以考虑创建
x
作为list
类的特例,并使用其自己的print方法。flseospp2#
假设示例模拟了您的数据结构,下面是一个可能的解决方案:
创建于2022年12月20日,使用reprex v2.0.2
然后,您可以使用
write.csv()
和对象out
来获取CSV文件。想法来源:https://www.r-bloggers.com/2021/12/an-easy-to-convert-list-to-long-table/
r55awzrz3#
如果所有列表都完成了,我们可以使用
cbind
的回收能力:输出(
csv
):