From ligges at statistik.uni-dortmund.de  Mon Jul 12 16:35:08 2004
From: ligges at statistik.uni-dortmund.de (ligges@statistik.uni-dortmund.de)
Date: Mon Jul 12 16:35:50 2004
Subject: [Rd] read.table, read.fwf, and na.strings (PR#7075)
Message-ID: <20040712143508.BAA80FC04@slim.kubism.ku.dk>

rmh@temple.edu wrote:

> # Your mailer is set to "none" (default on Windows),
> # hence we cannot send the bug report directly from R.
> # Please copy the bug report (after finishing it) to
> # your favorite email program and send it to
> #
> #       r-bugs@r-project.org
> #
> ######################################################
> 
> 
> Is this intended behavior for the read.fwf(na.strings="-999")?
> I anticipated that the na.strings would be padded with blanks.
> Therefore I anticipated getting the result tmp2 from the simpler
> na.strings in the tmp1 assignment?  My anticipation is based on the
> documentation that says
> "Blank fields are also considered to be missing values."
> 
> 
>>na.strings: a vector of strings which are to be interpreted as 'NA'
>>          values.  Blank fields are also considered to be missing
>>          values.
> 
> 
> 
> temp.dat

A blank field in the first column of the first row is:

   3456-999 01234
56-9990123412345

The field "-999 " cannot assumed to be blank in any sence from my point
of view.

Anyway, improving NA handling in read.fwf() is certainly something for
the wishlist (particularly padding blanks for na.string(s)). Is anybody
out there going to contribute (given anybody else thinks it is useful)?

Uwe Ligges



> ----------------
> 123456-999 01234
> 56-9990123412345
> ----------------
> 
> read.fwf.test.r
> ------------------------------------------------
> tmp1 <- read.fwf("temp.dat",
>                  na.strings="-999",
>                  col.names=LETTERS[1:4],
>                  widths=c(2,4,5,5))
> tmp1
> tmp2 <- read.fwf("temp.dat",
>                  na.strings=c("-999","-999 "),
>                  col.names=LETTERS[1:4],
>                  widths=c(2,4,5,5))
> tmp2
> ------------------------------------------------
> 
> 
> 
>>tmp1
> 
>    A    B    C     D
> 1 12 3456 -999  1234
> 2 56   NA 1234 12345
> 
>>tmp2
> 
>    A    B    C     D
> 1 12 3456   NA  1234
> 2 56   NA 1234 12345
> 
> 
> --please do not edit the information below--
> 
> Version:
>  platform = i386-pc-mingw32
>  arch = i386
>  os = mingw32
>  system = i386, mingw32
>  status = 
>  major = 1
>  minor = 9.1
>  year = 2004
>  month = 06
>  day = 21
>  language = R
> 
> Windows XP Home Edition (build 2600) Service Pack 1.0
> 
> Search Path:
>  .GlobalEnv, file:c:/HOME/rmh/hh/splus.library/HH/.RData, package:methods, package:stats, 
> package:utils, package:multcomp, package:mvtnorm, package:abind, package:graphics, 
> package:lattice, package:grid, Autoloads, package:base
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel


[Rd] read.table, read.fwf, and na.strings (PR#7075)
ligges@statistik.uni-dortmund.de