【发布时间】:2014-10-20 02:25:46
【问题描述】:
如何将 data.frame abc 添加/附加到我之前打开的文本文件中。我正在向该文件写入一些重要信息,然后我想将该 data.frame 附加到该信息下方。当我尝试使用 cat 编写 data.frame abc 时出现错误。
fileConn<-file("metadata.txt","w+")
smoke <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE)
smoke <- as.data.frame(smoke)
table <- sapply (smoke, class)
abc <- data.frame(nm = names(smoke), cl = sapply(unname(smoke), class))
cat("some imp info","\n", file=fileConn)
cat(abc,"\n", file=fileConn)
close(fileConn)
class(abc)
【问题讨论】:
-
capture.output(abc, file = fileConn)也可以 -
@lukeA 它有效。请添加它作为答案,我会接受它