[R] format \Sexpr{}

Felipe Carrillo mazatlanmexico at yahoo.com
Fri Feb 6 22:19:11 CET 2009


marc:
Thanks for the quick reply. I learned something new today, I wasn't aware of the big.mark argument.



--- On Fri, 2/6/09, Marc Schwartz <marc_schwartz at comcast.net> wrote:

> From: Marc Schwartz <marc_schwartz at comcast.net>
> Subject: Re: [R] format \Sexpr{}
> To: mazatlanmexico at yahoo.com
> Cc: r-help at stat.math.ethz.ch
> Date: Friday, February 6, 2009, 12:39 PM
> on 02/06/2009 02:32 PM Felipe Carrillo wrote:
> > Hi everyone: It is probably something simple but I
> can't find
> > anything related to this. Could someone show me how to
> format the sum
> > of x. the result is 10000 but I need comma formatted
> like this:
> > 10,000. Since I am going to be using this number to be
> added to
> > another calculation, I want to be able to remove the
> comma from the
> > 10,000 value. Thanks
> > 
> > x <- c(2000,3000,5000) this is the sum of x:
> \Sexpr{sum(x)}
> 
> See ?format and/or ?prettyNum and take note of the
> 'big.mark' argument:
> 
> x <- c(2000,3000,5000)
> 
> > sum(x)
> [1] 10000
> 
> > format(x, big.mark = ",")
> [1] "2,000" "3,000" "5,000"
> 
> > format(sum(x), big.mark = ",")
> [1] "10,000"
> 
> Note that these will be character vectors, not numeric, so
> be sure to
> retain the original numeric value(s) for subsequent math
> ops.
> 
> HTH,
> 
> Marc Schwartz




More information about the R-help mailing list