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

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Thu, 05 Jun 2008 13:57:53 +0200

Alberto Monteiro wrote:
> Of course this is a trivial task:
>
> text.in <- readLines(file.in)
> matrix.in <- strsplit(text.in, "[ \t]+")

You probably want

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

Uwe Ligges

> # matrix.out <- transpose matrix.in
> # loop over the lines of matrix.out creating text.out
> writeLines(text.out, file.out)
>
> What is the _most elegant_ way to write the transposition of
> matrix.in (that is _not_ a matrix) and the pasting of the
> lines of matrix.out?
>
> Alberto Monteiro
>
> PS: this is not a homework, this is evangelism to a Visual Basic
> programmer :-)
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 05 Jun 2008 - 13:38:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 Jun 2008 - 14:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive