[R] read.fortran format
    Steven Yen 
    syen04 at gmail.com
       
    Sat May 28 00:15:07 CEST 2016
    
    
  
Thanks John. That helped, but I got a mixed of good thing and bad thing. 
Good is R does not like the scientific number format "3E15.9" but I was 
able to read with alphanumerical format "3A15" (and convert to 
numerical). Bad is R does not like the numbers .1234, .2345 without the 
zeros before the decimal points. My data look like:
   1950. .614350 .026834 .087227 .006821 .180001 .084766
The first variable was read correctly, followed by six 0's.
As the instructions say, this fortran format is approximation at best 
and in this case, a poort approximation.
On 5/27/2016 2:21 PM, John McKown wrote:
> On Fri, May 27, 2016 at 12:56 PM, Steven Yen <syen04 at gmail.com 
> <mailto:syen04 at gmail.com>>wrote:
>
>     Dear fellow R users:
>     I am reading a data (ascii) file with fortran fixed format, containing
>     multiple records. R does not recognize fortran's record break (a
>     slash).
>     I tried to do the following but it does not work. Help appreciated.
>
>       60
>     FORMAT(1X,F6.0,5F8.6/1X,5F8.4,F10.6/1X,2F6.0,3E15.9,F8.0,F5.2,F5.3
>           *      /1X,F7.0,2E15.9,F9.4,F5.3)
>
>     mydata<-read.fortran("G:/Journals/Disk1/12_restat_95/estimate/GROUPD.DAT",
>     
>              c("1X","F6.0","5F8.6"/"1X","5F8.4","F10.6"
>               /"1X","2F6.0","3E15.9","F8.0","F5.2","F5.3"
>               /"1X","F7.0","2E15.9","F9.4","F5.3"),
>     
>     col.names=c("year","w1","w2","w3","w4","w5","w6","v1","v2","v3",
>     "v4","v5","v6","z","chyes","chno","ec","vc","cvc",
>     "pop","ahs","fah","tnh","eq","vq","ups","zm1 "))
>
>
> Did you see this from ?read.fortran
>
> <quote>
>
>  For a single-line record, ‘format’ should be a character vector.
>    For a multiline record it should be a list with a character vector
>    for each line.
>
> </quote>
>
> I think (not sure) you need:
>
> mydata<-read.frotran("G:/Journals/Disk1/12_restat_95/estimate/GROUPD.DAT",
> list(c("1X","F6.0","5F8.6"),c("1X","5F8.4","F10.6"),c("1X","2F6.0","3E15.9","F8.0","F5.2","F5.3"),c("1X","F7.0","2E15.9","F9.4","F5.3")).
> 
> col.names=c("year","w1","w2","w3","w4","w5","w6","v1","v2","v3",
> "v4","v5","v6","z","chyes","chno","ec","vc","cvc",
> "pop","ahs","fah","tnh","eq","vq","ups","zm1 "))
>
>
>
>
>
> -- 
> The unfacts, did we have them, are too imprecisely few to warrant our 
> certitude.
>
> Maranatha! <><
> John McKown
	[[alternative HTML version deleted]]
    
    
More information about the R-help
mailing list