Re: [R] write.fortran

2010-03-10 Thread Berend Hasselman
baptiste auguie-5 wrote: I'm trying to write tabular data to a text file, these data will be the input of a Fortran program. The format needs to be (i7,2x,7(e15.7,2x)). I have not been able to find a clean way of producing this output with write.table. I searched for a write.fortran

Re: [R] write.fortran

2010-03-10 Thread Berend Hasselman
baptiste auguie-5 wrote: This is a lot easier for(k in seq(1,nrow(m))){cat(c(sprintf(%7d,m[k,1]),sprintf(%16.7e,m[k,2:8]),\n)) Berend Oops. Missing sep= and closing }. The correct line is for(k in seq(1,nrow(m))){cat(c(sprintf(%7d,m[k,1]),sprintf(%16.7e,m[k,2:8]),\n),sep=)}

Re: [R] write.fortran

2010-03-10 Thread baptiste auguie
Thanks, it is indeed a bit cleaner. I was hoping for a more generic solution but I guess people use cat() and sprintf() in such cases. Thanks, baptiste On 10 March 2010 12:46, Berend Hasselman b...@xs4all.nl wrote: baptiste auguie-5 wrote: This is a lot easier  for(k in

Re: [R] write.fortran

2010-03-10 Thread Gabor Grothendieck
Try this. It takes a matrix or data.frame, codes= which is a vector of % codes and other text and file= and other cat arguments. If no ... args are given it outputs the character string that it would have handed to cat. write.mat - function(mat, codes, sep = , ...) { s - do.call(sprintf,

Re: [R] write.fortran

2010-03-10 Thread baptiste auguie
That's perfect, thanks! baptiste On 10 March 2010 14:47, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this.  It takes a matrix or data.frame, codes= which is a vector of % codes and other text and file= and other cat arguments.  If no ... args are given it outputs the character