2

I have a matrix and I would like to write it below 2 lines of text.

line #1 is here  
line #2 is here  
Table

I can write the table easily but is there way to append line of text above it?

table = matrix(1:9, nrow = 3, ncol = 3)
write.table(table, "data.txt", sep="\t") 
Ahdee
  • 4,679
  • 4
  • 34
  • 58
  • Have you tried [writing text to a file](http://stackoverflow.com/questions/2470248/write-lines-of-text-to-a-file-in-r) and then using `write.table(...., append = T)` ? – R. Schifini Jan 14 '16 at 03:57
  • @R.Schifini yes I just did the exact thing and came here to post it. thanks! – Ahdee Jan 14 '16 at 04:05

1 Answers1

4

found a solution!

a = matrix(1:9, nrow = 3, ncol = 3, dimnames = list(LETTERS[1:3], LETTERS[1:3]))
cat("World \n",file="a.csv")
write.table(a, 'a.csv',sep=",",append=TRUE, col.names=NA)
Ahdee
  • 4,679
  • 4
  • 34
  • 58