0

I want to write a file and add new data to it in a seperate column. New data is added multiple times (12). sounds easy and there is lots of solutios available (use write.table and not write.csv, how to use write.table, ETH explanation on write.table) So I tried the following lines of code unsuccessfully. The new data is always added at the bottom of the first column.

    write.table(df$c1, file="name.csv", row.names=F, col.names=F, append=T, sep=",")
    write.table(df$c1, file="name.tsv", row.names=F, col.names=F, append=T, sep="\t")
    sapply(df$c1, write.table, file="name.csv", append=TRUE, sep=",")

Above codes work for other users. I don't understand why they dont work in my case.

Community
  • 1
  • 1
Simone
  • 497
  • 5
  • 19
  • There is `)` missing on the first line? – zx8754 Jul 25 '16 at 10:42
  • @zx8754 yes thanks. Though that doesn't explain why it isn't working ;-) – Simone Jul 25 '16 at 12:58
  • 1
    How your `df$c1` looks like? Another approach would be, read the table, cbind the column, write the table by replacing the old one. – Roman Jul 25 '16 at 13:01
  • @Jimbou that is an excellent idea. The only issue is that my df is in fact an unequally sized matrix. Above idea was my work around of [this unsolved problem](http://stackoverflow.com/questions/38540949/r-repeatedly-cbind-a-matrix-a-vector-of-unequal-length-vector-goes-into-n?noredirect=1#comment64520013_38540949) R seems to handle unequally sized matrices not well :-( – Simone Jul 25 '16 at 13:16
  • @Simone `cbind.na` from the qpcr package could handle your problem. http://www.inside-r.org/packages/cran/qpcR/docs/cbind.na – Roman Jul 25 '16 at 13:26

0 Answers0