[R] Unexpected behaviour of read.table

David Clayton david.clayton at mrc-bsu.cam.ac.uk
Sat May 29 19:29:16 CEST 1999


When reading comma-delimited files as saved from a spreadsheet (unfortunately 
many of my scientific collaborators give me these) in read.table(), missing 
values are spotted most of the time. Unfortunately when comma is the first 
character on the line it gets it wrong. For example, reading the file

 
1,,3
 ,5,6
,8,9 

with 

read.table("test.dat", header=F, sep=",")

R gives an error:
row.lens=
[1] 3 3 2
Error: all rows must have the same length.

Splus handles this OK and returns

  V1 V2 V3 
1  1 NA  3
2 NA  5  6
3 NA  8  9

as expected.

Note that this discrepancy does NOT occur with scan(..., sep=","), which 
returns

1 NA  3 NA  5  6 NA  8  9

in both R and Splus.





David Clayton

MRC Biostatistics Unit
Institute of Public Health
University Forvie Site
Robinson Way
Cambridge CB2 2SR

Telephone: (0) 1223 330375
Fax:       (0) 1223 330388

e-mail: david.clayton at mrc-bsu.cam.ac.uk



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