[R] printf and friends in R?

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Tue Jul 15 13:25:44 CEST 2003


(Ted Harding) wrote:

help.search("printf") reveals the sprintf function (amongst others).

> 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

 > sprintf("Case %d#%.2f#%.2f%.4f\n", as.integer(n),x1,x2,x3 )
[1] "Case 10#3.21#7.650.4321\n"

  Note it returns a formatted string, which you can then print or cat if 
you want it output to screen. If you cat it then the \n will be a 
carriage return.


Baz




More information about the R-help mailing list