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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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. IIt 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._