You may also see a problem with line names that are identical, because write.table does not allow identical line names when adding. You can try. In the first write to the file, try write.table with only row.names = FALSE . Then, starting with the second entry in the file, use both col.names = FALSE and row.names = FALSE
Here is the first entry in the file
> d1 <- data.frame(A = 1:5, B = 1:5) ## example data > write.table(d1, "file.txt", row.names = FALSE)
We can verify this with read.table("file.txt", header = TRUE) . Then we can add the same data frame to this file using
> write.table(d1, "file.txt", row.names = FALSE, col.names = FALSE, append = TRUE)
And again, we can verify this with read.table("file.txt", header = TRUE)
So, if you have a list of data frames, say dlst , your code snippet that adds data frames together may look something like
> dlst <- rep(list(d1), 3) ## list of example data > write.table(dlst[1], "file.txt", row.names = FALSE) > invisible(lapply(dlst[-1], write.table, "file.txt", row.names = FALSE, col.names = FALSE, append = TRUE))
But, as @MrFlick suggests, it would be much better to add data frames to R and then send them to a file once. This will fix many possible errors / problems that may occur when writing to a file. If the data is in the list, this can be done using
> dc <- do.call(rbind, dlst) > write.table(dc, "file.txt")