[R] problem with read.fwf

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Jun 13 16:54:40 CEST 2002


On 13 Jun 2002, Peter Dalgaard BSA wrote:

> "MATT BORKOWSKI" <mpb170 at psu.edu> writes:
>
> > Here is an example of the data I'm reading in using read.fwf:
> >  5342.0 5450.4  0.9200  0.4506 34.7030 27.8411 37.1306 46.0034  0.0000
> >  5438.0 5549.6  0.9300  0.4477-34.7280 27.8616 37.1506 46.0234  0.0000
> >
> > And the commands I'm using to read it in:
> >    widths <- c(7,7,8,8,8,8,8,8,8)
> >    filedata <- read.fwf(fileopen, widths,sep="",dec=".")
> >
> > The problem is with reading the second line above.  R gives an error telling me
> > that there are not 9 data points in that line.  I tried adding fill=TRUE to the read
> > statement but then when I check the data.frame I'm reading the data into...the
> > second line has been read in as:
> >
> > 5438 5549.6 0.93 0+0i 27.8616 37.1506 46.0234  0 NA
>
> Not what happens in the current version (the complex conversion is a
> bug which has since been corrected), but that's not the source of the
> problem.
>
> read.fwf works by reading the data as lines, splitting it according to
> the widths, writing the fields to a temporary file separated by "sep",
> and reading it back in with the same separator. Using sep="" is what
> is doing you in...

Or as the help page puts it

     sep: character; the separator used internally; should be a
          character that does not occur in the file.

and "" is not a character.


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