[R] skipping fields in scan()

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jan 4 08:38:12 CET 2002


On Thu, 3 Jan 2002, Vadim Ogranovich wrote:

> Dear R-Users,
>
> Is it possible to instruct scan() to skip fields when reading from a file.
> Here is an example. Suppose I have a three-column table file, "foo"
>
> 1 2 3
> 4 5 6
>
> and I want to read in only the first and the third columns skipping the
> second. If memory serves me well (though I might be wrong), in S-Plus you
> could accomplish this by putting NULL in the respective position of the
> list, e.g.
>
> scan("foo", list(a=integer(0),NULL,c=integer(0)))
>
> Is there a similar construct in R?

Not at present, but I plan to add it soon (for 1.5.0).

> For a workaround I know I can read the whole thing and then drop the
> unneeded column(s), or alternatively I can preprocess the file with a Perl
> script, but before that I'd like to make sure there is no a more direct way
> of doing this.

Normally the first is sufficient in R.

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