I have information that is contained in vectors, for example:
sequence1<-seq(1:20)
sequence2<-seq(21:40)
...
I want to append that data to a file, so I am using:
write.table(sequence1,file="test.csv",sep=",",append=TRUE,row.names=FALSE,col.names=FALSE)
write.table(sequence2,file="test.csv",sep=",",append=TRUE,row.names=FALSE,col.names=FALSE)
But the issue is that this is added all in one column like:
1
2
3
...
21
22
...
40
I want to add that data in columns so that it ends up like:
1 21
2 22
3 23
... ...
20 40
How I can do that using R?
write.tablewrites a data.frame or matrix to a file. If you want two write a two-column data.frame (or matrix) to a file usingwrite.table, then you need to create such an object inRSee
?write.tablefor a very clear description of what the function does.As stated by @JoshuaUlrich’s comment, this is not really an
Rissue, you can’t append a column to a csv file due to the way it is stored on disk.