[R] How to import specific column(s) using "read.table"?

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 9 22:56:42 CEST 2004


There is no way for read.table to skip columns.  It is however very easy 
to do this with a preprocessing of the table: cut, awk and perl all come 
to mind, and you could do it in R too, reading a block of rows at a time 
and writing them back out.

scan() can skip columns, but I would still use preprocessing with scan.

On Mon, 9 Aug 2004, F Duan wrote:

> I have a very big tab-delim txt file with header and I only want to import 
> several columns into R. I checked the options for "read.table" and only 
> found "nrows" which lets you specify the maximum number of rows to read in. 
> Although I can use some text editors (e.g., wordpad) to edit the txt file first 
> before running R, I feel it’s not very convenient. The reason for me to do this 
> is that if I import the whole file into R, it will eat up too much of my 
> system’s memory. Even after I remove it later, I still can’t release the memory.

The peculiar quotes suggest this is Windows -- the Rtools we use to build 
R there contain a cut.exe.

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




More information about the R-help mailing list