[R] Hyper-elegant code to get a text file, transpose it, and write it

Alberto Monteiro albmont at centroin.com.br
Thu Jun 5 14:26:08 CEST 2008




Uwe Ligges wrote:
> 
> You probably want
> 
> write.table(t(read.table(file.in)), file = file.out, row.names = 
> FALSE, col.names = FALSE)
>
Ok, almost there. I forgot to tell (because I didn't know)
that the strings were separated by tabs (I just thought of
splitting by _any_ space), and that the output would also
be tab-separated. But there's still a minor feature:

write.table(t(read.table(file.in, sep ="\t")), file = file.out, 
  row.names = FALSE, col.names = FALSE, sep = "\t") 

writes each output enclosed with quotation marks, like:

"1/2/2003"	"0.5638"	"0.6233"	"0.4559"	"0.8746"

I didn't find in the documentation of write.table a way to
remove those quotes, because qmethod is either escape or double :-(

Alberto Monteiro



More information about the R-help mailing list