[R] skipping specific rows in read.table

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Apr 22 15:31:53 CEST 2002


On Mon, 22 Apr 2002, David Kane  <David Kane wrote:

> Hi,
>
> We are considering organizing some of our ascii files with multiple "column
> names" like so:
>
> a.long.but.complete.name	a.different.complex.name
> short.name.1	short.name.2
> 1	7
> 2	8
> 3	9
> [more data]
>
> The basic idea is that we want to keep, in one location, both a long descriptive
> name of each variable (in row 1) and a short convenient name (in row 2). I
> could imagine keeping other information about the data in here as well.
>
> [Comment: Of course, my CS buddies would say that the "grown up" way to handle
> this sort of thing is XML, but I haven't seen much discussion of people reading
> XML files directly into R -- although Duncan Temple Lang's R/SPlus XML Parsing
> Package looks quite interesting. In any event, since I don't have complete
> control over the format of these files, my options may be limitted. I would
> certainly love to hear about any XML/R success stories.]
>
> In any event, I can easily use the "skip" argument to read.table to ignore the
> first row.
>
> > read.delim("/home/a296180/tmp/junk.txt", skip = 1)
>   short.name.1 short.name.2
> 1            1            7
> 2            2            8
> 3            3            9
>
> Is there a similar trick for ignoring the second row? That is, I want to
> produce a dataframe that looks like:
>
>   a.long.but.complete.name a.different.complex.name
> 1                        1                        7
> 2                        2                        8
> 3                        3                        9

Use the facilities of connections to read two lines and push back the
first one.

[...]

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list