0

I am writing a vector to a file in R. However the output comes on 2 lines. I wanted all the values to come on a single line. Can you let me know how to fix this

write(value,file=fileconn,append=TRUE,sep="\t") 

The o/p comes as follows

1777.167 1825.167 1873.167 1921.167 1969.167

2017.167

Regards Ganesh

4
  • 1
    can you please provide dput(value) Commented Jan 15, 2015 at 5:07
  • 1
    That's what I was going to suggest too cat(value, file = "filename") might be better. And then you can use scan to read it back in. I'm also curious to know what fileconn is. Is that a connection? Commented Jan 15, 2015 at 5:25
  • @Mr.Flick Thanks. I did not realize that write had a ncolumns parameter. I did check on other vectors and I did notice that it defaulted to 5 columns. I added ncolumns and it is fine write(value,file=fileconn,append=TRUE,sep="\t",ncolumns=7) Commented Jan 15, 2015 at 6:10
  • @Richard the file columns is a connection fileconn <-file(filename) Commented Jan 15, 2015 at 6:13

1 Answer 1

2

I'm not sure write() is probably not the best choice, but if you want to use it, it might be a good idea to check the ?write help file. It does have an ncolumns= parameter which defaults to 5 for simple numeric vectors.

I would think cat() would be a better solution for just dumping numeric vectors.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.