将列表写入txt文件

时间:2020-06-29 17:18:20

标签: r

在处理完这些段落后,我想将它们的列表写到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."

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您正在寻找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")
相关问题