[R] problem with read.fwf
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu Jun 13 16:36:57 CEST 2002
"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...
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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