[R] Formatting numerical output

Berend Hasselman bhh at xs4all.nl
Sun Apr 25 11:01:50 CEST 2010



MARCEL CURLIN wrote:
> 
> .....
> 
> Currently my output looks like:
> [1] Excluded range: Time 0                    0.2                 
> [4] R^2 =                0.111526872884505   
> [1] Excluded range: Time 0.2                  0.4                 
> [4] R^2 =                0.0706332920267015  
> [1] Excluded range: Time 0.4                  0.6                 
> [4] R^2 =                0.0691466100802879
> 
> I would like the output format to look like:
> Excluded range: Time 1.0 - 1.2<tab>R^2 = 0.45  
> Excluded range: Time 1.2 - 1.4<tab>R^2 = 0.5
> etc.
> 
> I would like to 
> 1. get time and R^2 data on the same line
> 2. control (reduce) the number of digits reported for R^2
> 3. reduce the large number of empty spaces between "R^2' and value.
> 

?sprintf

For example

cat(sprintf("Excluded range: Time %.2f %.2f R^2 =
%.4f\n",lowend,highend,rsquare))

Berend

-- 
View this message in context: http://r.789695.n4.nabble.com/Formatting-numerical-output-tp2063882p2064114.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list