Hi I got a problem with creating a textfile: how can I create a textfile, which has a headline like: #data1 1 2 3 4 5 6 7 8 the problem is, how to bind text and matrix, so that the "read.table"-function will ignore the text and read the numbers. Thank you for help Michael -- 2
"sink" may be the simplest but won't give you the control you may want. For full control, have you considered "cat" and "write.table"? Both have "append" arguments plus others. hope this helps. spencer graves michael kirschbaum wrote:> Hi > I got a problem with creating a textfile: > how can I create a textfile, which has a headline like: > > #data1 > 1 2 3 4 > 5 6 7 8 > > the problem is, how to bind text and matrix, so that the > "read.table"-function > will ignore the text and read the numbers. > > Thank you for help > Michael >
[read text file :]> #data1 > 1 2 3 4 > 5 6 7 8Is this what you mean ?> b <- read.table("filewithyourdata", header=F, sep=" ") > bV1 V2 V3 V4 1 1 2 3 4 2 5 6 7 8 HTH, Tobias
Sorry Michael, I should read more carefully. You asked to create the file, not to read it. Tobias
One way might be to use a connection and `writeLines'. For example:> a <- matrix(1:8, byrow = TRUE, ncol = 4) > a[,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8> con <- file("testfile.txt", "w") > writeLines("#data", con) > write(a, con, ncol = 4) > close(con) >-roger michael kirschbaum wrote:>Hi >I got a problem with creating a textfile: >how can I create a textfile, which has a headline like: > >#data1 >1 2 3 4 >5 6 7 8 > >the problem is, how to bind text and matrix, so that the >"read.table"-function >will ignore the text and read the numbers. > >Thank you for help >Michael > > >