reading "special" text files
On Wed, 24 Aug 2005, Jan Wiener wrote:
hello, assume you have a txt-file (sep="\t" or "") looking as follows that you want to read into a variable:
Into a variable or a data frame?
1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 the result should look like this (e.g., in a data.frame):
With no column names? Not possible.
1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 is there any way to do so?
I think we need to know what the structure here is. At a guess, the separator is multiple tabs as in the example. In that case
read.table("foo", header=FALSE, fill = TRUE)
V1 V2 V3 V4 V5 V6 1 1 1 2 3 NA NA 2 2 1 2 3 4 NA 3 3 1 5 6 7 8 or
read.table("foo", header=FALSE, fill = TRUE, row.names=1)
V2 V3 V4 V5 V6 1 1 2 3 NA NA 2 1 2 3 4 NA 3 1 5 6 7 8 does in essence what you want.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595