[R] F10.1 and i3 format in R

Duncan Murdoch murdoch.duncan at gmail.com
Mon Mar 10 14:34:32 CET 2014


On 10/03/2014 9:22 AM, Stefano Sofia wrote:
> Dear list members,
> I have to export (through 'write.table')

Why restrict yourself to write.table?
> a dataframe where two columns must be respectively F10.1 (floating with 10 digits, 1 of which for the

That's not the usual meaning for F10.1: normally the 10 char width 
includes the decimal point, not just the digits.
> decimal position) and i3 (integer of length 3).
> I looked at the 'format' options, but I couldn't see what I need.

I'd suggest converting the numbers to character vectors in the right 
format, then writing those out (perhaps with write.table, but not 
necessarily).

sprintf() uses C-like format strings, where "%10.1f" is close to F10.1, 
and "%3d" is close to i3. You could convert all of the numbers at once 
and use writeLines, e.g.

writeLines(somefile, sprintf("%10.1f%3d", f, i))

will pack two numbers per line with no extra spaces between.

Duncan Murdoch
> I also looked for some examples, with no success.
> Is it possible to do it within R without external work?
>
> Thank you for your help
> Stefano
>
>
>
> ________________________________
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list