[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:07:03 CEST 2008


Uwe Ligges 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)
>
Unfortunately, it doesn't work. In fact, read.table(file.in) returns
an error:

Erro em scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  linha 1 não tinha 1362 elementos

which means
  line 1 does not have 1362 elements

(whatever that means!)

Alberto Monteiro



More information about the R-help mailing list