[R] printf and friends in R?
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Tue Jul 15 12:33:24 CEST 2003
Hi folks
Does R have anything straightforwardly resembling the commands
fprintf, sprintf, printf (derived from C, and present in octave
and matlab)?
As in printf(format_string, ... )
where "format_string" defines the print format (including any
fixed text) and "..." is a list of variables whose values are
to be inserted into the line.
Example:
printf("Case %d#%.2f#%.2f%.4f\n", n,x1,x2,x3 )
which would output a line like
Case 10#3.21#7.65#0.4321
this particular case being a line in the right format for processing
by groff's 'tbl' table-formatter. In fact you could write the whole
table definition using printf:
printf(".TS\ntab(#);\nr n n n.\n"
for(i in (1:nrow(X))){
printf("Case %d#%.2f#%.2f%.4f\n", n,X[i,1],X[i,2],X[i,3] )
}
printf(".TE\n")
Other variants could be used for similar purposes.
(If something like this is not already around in R, I suppose it
wouldn't be too difficult for me to write it; but it's worth asking
first!)
Thanks,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 15-Jul-03 Time: 11:32:39
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list