[R] read data in from gzipped file

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Jun 27 22:00:50 CEST 2001


On Wed, 27 Jun 2001, Paul E Johnson wrote:

> Until the postings today about gzfile, I did not realize R can read in
> from gzipped datafiles.  So I'm testing that to see how it works.  I

It couldn't until last Friday ... and it is in the NEWS for 1.3.0.

> took a test file, which has headers, which I previously used with
> read.table(), and tried to turn a gzipped version into a R dataframe.
>
> > myFile <- gzfile("DataCulture22.gz", open = "r")
> > splat <- readLines(myFile)
>
> The object splat is a vector of character strings:
> > is.vector(splat)
> [1] TRUE
>
> And  my headers are there:
> > splat[[1]]
> [1] "T Run Seed  IntAct  Change f0 f0T0 f0T1 f0T2 average0 variance0
> relentropy0 f1 f1T0 f1T1 f1T2 average1 variance1 relentropy1 f2 f2T0
> f2T1 f2T2 average2 variance2 relentropy2 f3 f3T0 f3T1 f3T2 average3
> variance3 relentropy3 f4 f4T0 f4T1 f4T2 average4 variance4 relentropy4
> totalEntropy acquaint harmony identical "

You want

splat <- read.table(gzfile("DataCulture22.gz"), header=T)

or whatever else you would add for an uncompressed data file
(open ="r" is the default).


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