[Rd] More on scan: extra field at end of line

Peter Kleiweg kleiweg@let.rug.nl
Tue, 26 Dec 2000 14:42:07 +0100 (CET)


Suppose, I have a file "data1" containing:

    450   390   467   654    30   542   334   432   421
    357   497   493   550   549   467   575   578   342
    446   547   534   495   979   479

I can read this file with:

    scan("data1")
    Read 24 items
     [1] 450 390 467 654  30 542 334 432 421 357 497 493 550 549 467 575 578 342 446
     [20] 547 534 495 979 479    

But now, suppose I have a file "data2" containing:

    450, 390, 467, 654,  30, 542, 334, 432, 421,
    357, 497, 493, 550, 549, 467, 575, 578, 342,
    446, 547, 534, 495, 979, 479

When I try to read this with sep="," I get:

    scan("data2", sep=",")
    Read 26 items
     [1] 450 390 467 654  30 542 334 432 421  NA 357 497 493 550 549 467 575 578 342
     [20]  NA 446 547 534 495 979 479 

I get two extra fields, both NA. Not what I'd want. And I can't
drop the NA's, because there could be other NA's, not resulting
from this comma-EOL combination.

I suggest, the proper action for scan would be to treat the
combination sep plus newline as a single separator.

-- 
Peter Kleiweg
http://www.let.rug.nl/~kleiweg/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._