Writing a data frame with cat

How to add / add data.frame abc file to a text file that I opened earlier. I write some important information to this file, and then I want to add this data.frame below this information. I get an error when trying to write data.frame abc using cat.

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) 
+5
source share
2 answers

Just use standard tools to write data.frame , i.e. write.table :

 write.table(abc, 'yourfile', append=TRUE) # plus whatever additional params 
+2
source

try it

 capture.output(abc, file = fileConn) 
+2
source

Source: https://habr.com/ru/post/1201172/


All Articles