假设有一本书的列表及其作者,将数据读入一个名为“LS”的列表后,我试图将其输入文件中,但输出结果为:
> write.table(LS, "output.txt")
Error in data.frame(..., title = NULL, :
arguments imply differing number of rows: 1, 0
> write(LS, "output.txt")
Error in cat(list(...), file, sep, fill, labels, append) :
argument 1 (type 'list') cannot be handled by 'cat'
我能够使用dput,但我希望数据格式良好(文件中不重复出现关键字)。有什么建议吗? 谢谢
更新 dput(head(LS, 2))
list(structure(list( title = "Book 1",
authors = list(structure(c("Pooja", "Garg"),
.Names = c("forename","surname")),
structure(c("Renu", "Rastogi"),
.Names = c("forename","surname")))),
.Names = c("title", "authors")),
structure(list( title = "Book 2",
authors = list(structure(c("Barry", "Smit"), .Names = c("forename",
"surname")), structure(c("Tom", "Johnston"), .Names = c("forename",
"surname")))), .Names = c("title", "authors")))
dput(head(LS,2))
,这样我们就可以看到数据的结构。 - mnelsave
。 - Aaron left Stack Overflow