[R] Formatted output with alternating format at different rows

Ray Laymon ray.laymon064 at gmail.com
Mon Jan 3 16:38:29 CET 2011


Dear all,

I have a simple question. I couldn't find a solution in the
forums/R-user manual; I have also asked to my friends who use R, but
couldn't get any answer from them either. I would appreciate any
solutions.

I want to write formatted text file like in Fortran. More specifically
with the format choice of mine for any given line (more specifics are
given below).

The R function read.fortran() read files like in Fortran, but I
couldn't find any function to write files in a similar way..

Since I want different formats for different lines, write(),
write.table(), write.fwf() functions didn't work for me.

Thanks for your time

Ray




##########
##########
In Fortran
##########

real dummy3(3)
real dummy4(4)
real dummy2(2)

dummy3 = (/1.1, 2.2, 3.3/)
dummy4 = (/4.4, 5.5, 6.6, 7.7/)
dummy2 = (/8.8, 9.9/)

OPEN(UNIT=320,FILE='output.dat',FORM='FORMATTED')
write(320,501) dummy3
write(320,502) dummy4
write(320,503) dummy2
close(320)

501 format(F5.1,F6.2,F7.3)
502 format(F5.2,F6.3,F7.4,F8.5)
503 format(F5.3,F6.4)
##########
##########

This should produce an output something like below (I used * instead
of the spaces)

**1.1**2.20***3.300
*4.40*5.500**6.6000*7.70000
8.8009.9000

And a function in [R] that will enable me to write something like
above is what I am looking for..
##########
##########
##########



More information about the R-help mailing list