How can I add/append data.frame abc to the text file that I have opened previously. I am writing some important information to that file and then I want to append that data.frame below that information. I get an error when I try to write the 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)
cat() function in R Language is used to print out to the screen or to a file.
print() returns a character vector. A vector is an object in R language. cat() returns an object NULL . cat() returns an object NULL .
The cat function is typically used to return character strings. The print function, however, is often also used for other data formats.
DataFrame is a 2-dimensional labeled data structure with columns of potentially different types. You can think of it like a spreadsheet or SQL table, or a dict of Series objects. It is generally the most commonly used pandas object.
Just use the standard tools for writing data.frame
's, i.e. write.table
:
write.table(abc, 'yourfile', append=TRUE) # plus whatever additional params
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With