首页 > 解决方案 > 将列表写入 txt 文件

问题描述

我想在操作后将段落列表写入 txt 文件以查看,调用列表psw_list,您可以使用psw_list$p1. psw_list$p1好像:

> psw_list$p1
[1] "For more than five years, William Sencion did the same task over and over. He signed onto the New York City’s housing lottery site and applied for one of the city’s highly coveted, below-market apartments. Each time, he got the same response: silence."

有任何想法吗?

标签: r

解决方案


write(...) 函数是您正在寻找的。如果要将所有段落写入一个文件,则需要使用 unlist(...) 函数,如下所示。

这些函数会将生成的 .txt 文件转储到您的工作目录中。

psw_list <- c()
psw_list$p1 <- "For more than five years, William Sencion did the same task over and over. He signed onto the New York City’s housing lottery site and applied for one of the city’s highly coveted, below-market apartments. Each time, he got the same response: silence."
psw_list$p2 <- "Something something dark side. Luke I am your father."

write(psw_list$p1, "first_paragraph.txt")
write(unlist(psw_list), "all_pragraphs.txt")

推荐阅读