[R] formatting in r

jim holtman jholtman at gmail.com
Wed Jul 29 03:35:26 CEST 2009


If you want to "mix" alphanumeric and numerics, the 'sprintf' is one
way of doing it:

> u <- 140
> xbar <- 150
> alpha <- .05
> zcrit <- 1.6449
> zcrit2 <- 1.96
> zstat <- 4
> pvalue <- 6.334348e-05
>
> cat(sprintf("u xbar alpha zcrit zcrit2 zstat pvalue %.0f  %.0f %.2f %.4f %.2f %.0f %e\n",
+     u, xbar, alpha, zcrit, zcrit2, zstat, pvalue))
u xbar alpha zcrit zcrit2 zstat pvalue 140  150 0.05 1.6449 1.96 4 6.334348e-05
>
> cat(sprintf("Critical Z = %.3f\n", zcrit))
Critical Z = 1.645
>
>


On Tue, Jul 28, 2009 at 1:36 PM, Mary A. Marion<mmstat at comcast.net> wrote:
> Hello,
>
> I have output that I want to print out.  I am having a few issues.
>
> 1] output u to power is really nothing more than a 2 x 11 set of values
> formed using cbind function
>   and printed out as a data frame
>   How can I get it to output over several lines such as seen here?
>
> 2] Critical Z etc. were added by hand.  I need an example of how I can mix
> alphanumeric
>   and numeric data on output.
>
> Can you assist?  R is proving to be a really fine computational language
> that is easy to use.
>
> Thank you.
> Sincerely,
> Mary A. Marion
>
>  u  xbar  alpha  zcrit  zcrit2  zstat        pvalue  140   150    .05 1.6449
>    1.96      4  6.334248e-05
>
>  LB95  UB95    LB90    UB90
>  145.1 154.9 145.888 154.112
>
>    Beta Power
>  0.021 0.979
>
>    Critical Z = 1.645
>    Zstatistic = 4
>    Empirical Mean   150    [ 135.1, 144.9 ) = Ao(µo)
>    Population Mean  140    [ 145.1, 154.9 ] = C(x)
>    Pvalue  < .0001
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list