Re: [R] reading "special" text files

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed 24 Aug 2005 - 20:02:34 EST

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@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

______________________________________________
R-help@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
Received on Wed Aug 24 20:16:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:55 EST