[R] Selective column loads with scan()
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Jan 7 20:42:16 CET 2001
On Sun, 7 Jan 2001, Uwe Ligges wrote:
> On Sun, 7 Jan 2001, Samir Mishra wrote:
>
> > Help!
> >
> > I have a very large data file with about 100 columns. Instead of loading
> > all of the columns using read.table() (my PC won't be able to handle the
> > resulting data frame), I'd like to read in one column of the datafile at
> > a time using scan() in conjunction with the 'what = ' option. I've tried
> > loading just the third column using -
> >
> > > scan(file.name, what = list(NULL, NULL, "", rep(NULL, 97)). ... )
> >
> > along with a couple of other options but I can't get the results I want
> > (if I avoid an error). For example -
> > > list(NULL, NULL, "", rep(NULL, 97))
> > [[1]]
> > NULL
> >
> > [[2]]
> > NULL
> >
> > [[3]]
> > [1] ""
> >
> > [[4]]
> > NULL
> >
> > is not what i'm looking for.
> >
> > Is there a better way to selectively read in individual columns from a tab
> > separated data file?
> >
> > I've done this before, and that makes this exercise even more frustrating.
>
>
> Try
>
> scan(file.name, what = list(, , ""), flush = TRUE)
Unfortunately that gives you the first column. With S you need the NULLs
in there (and then it is a known trick), but they are not accepted in R.
BTW,
> list(, , "")
[[1]]:
[1] ""
> list(NULL, NULL, "")
[[1]]:
NULL
[[2]]:
NULL
[[3]]:
[1] ""
are different.
I don't know a good way to do this in R, but then I would not try it.
Either use `cut' to extract the columns(s) needed from the file, or
use a database and a connection such as RODBC to do the extraction in the
database.
--
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