[R] problem with read.fwf
MATT BORKOWSKI
mpb170 at psu.edu
Thu Jun 13 16:09:10 CEST 2002
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
Correct me if I'm wrong...but I thought the whole point of read.fwf was to define
where values in a file begin and end. As a result...by defining this...shouldn't
0.4477 and -34.7280 be read in as different values since their widths have
been defined as 8 and 8? I assume my problem is occurring because R is trying
to read in 0.4477-34.7280 as one value. Is this a correct assumption? Or is
there another problem with the dataset or my code that I'm overlooking?
Is there anyway around this so that it will read in correctly? Thanks for your
time.
Matt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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