I need to write a text file that looks like this:
Header text More Header text 0 1 1 2 2 3 3 4 More text 0 2 1 4 2 6 3 9 The numeric values are stored in two data frames.
So I thought about using write.table that does exactly what I need. I was thinking of something like this:
header <- "Header text \n More Header text" df.text1 <- write.table(my.df1, row.names = FALSE, col.names = FALSE) more.text <- "More text" df.text2 <- write.table(my.df2, row.names = FALSE, col.names = FALSE) writeLines(paste(header, df.text1, more.text, df.text2, sep = "\n"), my.file) The problem is, write.table writes to a file or connection, and I don't know how to write in a string.