[R] read data in from gzipped file

Paul E Johnson pauljohn at ukans.edu
Wed Jun 27 21:46:32 CEST 2001


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

I do not understand how to get from there to a dataframe.  One
complication is that some of my data values are characters, as in 
> splat[[3]]
[1] "    10 22 388401534       165        12 f0 161  177  162  1.002000
0.644000 0.999131 f1 166  157  177  1.022000 0.684000 0.998906 f2 150 
167  183  1.066000 0.658000 0.997017 f3 167  157  176  1.018000 0.684000
0.999012 f4 168  169  163  0.990000 0.660000 0.999887 0.944053 0.330000
0.151200 0.007000 "

I'm reading MASS by Venables & Ripley 3ed p. 48 where it talks about
coercing a string vector into a data frame, but I just keep floundering
around trying to  make this work.  The recipe on p. 48 seems to require
I know how many variables there are in each row, but ahead of time I
don't always know.

Thanks in advance.

-- 
Paul E. Johnson                       email: pauljohn at ukans.edu
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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