[R] Append Columns
Adaikalavan Ramasamy
ramasamy at cancer.org.uk
Sun Sep 5 06:08:44 CEST 2004
Using append=TRUE in write.table only appends rows (see example below).
You might be interested in a recent tread about appending to save()
http://tolstoy.newcastle.edu.au/R/help/04/07/1467.html
> write.table( matrix(1:9, 3), file="aaa.txt", sep="\t" )
> write.table( matrix(101:109, 3), file="aaa.txt", sep="\t",
append=TRUE, col.names=FALSE )
> read.delim(file="aaa.txt", row.names=NULL)
row.names X1 X2 X3
1 1 1 4 7
2 2 2 5 8
3 3 3 6 9
4 1 101 104 107
5 2 102 105 108
6 3 103 106 109
Here are some possible solutions :
1) Read in the existing file first then use cbind and writing it back.
2) If you plan on doing this frequently (as in a loop), transpose your
problem so that you appending rows as above and after the last
iteration, transpose the results.
3) If you have access to unix/linux environments you can try the paste
command.
Regards, Adai
On Sat, 2004-09-04 at 20:25, Yao, Minghua wrote:
> Dear all,
>
> Can I use "write.table" to append columnns?
>
> Thanks for any help
>
> -MY
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list