[R] characters, mathematical expressions and computed values

William Dunlap wdunlap at tibco.com
Sat Nov 24 18:34:34 CET 2012


My message much earlier in the thread was
  > I think that bquote, with its .() operator, suffices for [almost?] any single title;
  > don't bother fiddling with expression(), substitute(), or parse().   (You can make
  > those work in many situations, but if you stick with just bquote then you can
  > spend your time on the title itself.)

I still think that is a good suggestion.  While you are learning this stuff, don't
even consider solutions that are not of the form
   main=bquote(...)
That leaves you with two of your nine attempts
  >  #chart 6:
  >  hist(x,main=bquote(paste("6. ",expression(bar(x))," = ",.(meanx))))
  > #chart 8:
  >  hist(x,main=bquote("Heart Attack (" * bar(X)==.(meanx) *")"))
I would ignore #6 as well because it has a call to expression() inside
the call to bquote.

What do you want to change about #8?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of mee1d3hs
> Sent: Saturday, November 24, 2012 5:21 AM
> To: r-help at r-project.org
> Subject: Re: [R] characters, mathematical expressions and computed values
> 
> I still can't get this to work, I am just trying to learn and this is
> supposed to be a feature of R, the ability to combine math notation in
> charts and exhibits
> 
> I did some more work to try to show what I am trying it to and what is not
> working
> 
>  x <- rnorm(1000,mean=10,sd=2)
> 
>  par(mfcol=c(3,3))
>  meanx <- round(mean(x),digits=2)
> 
>   x <- rnorm(1000,mean=10,sd=2)
> 
>  par(mfcol=c(4,2))
>  meanx <- round(mean(x),digits=2)
> 
>  #chart 1:
>  hist(x,main=paste(" 1. Mean of X =",bquote(.(meanx))))
>  #chart 2:
>  hist(x,main=paste(" 2. Mean of X = ",substitute(meanx,list(meanx=meanx))))
>  #chart 3:
>  hist(x,main=expression("3. "*bar(x)*" = "))
>  #chart 4:
>  hist(x,main=expression(paste("4. ",bar(x)," = ",bquote(.(meanx)))))
>  #chart 5:
>  hist(x,main=expression(paste("5. ",bar(x)," =
> ",substitute(meanx,list(meanx=meanx)))))
>  #chart 6:
>  hist(x,main=bquote(paste("6. ",expression(bar(x))," = ",.(meanx))))
>  #chart 7:
>  hist(x,main=paste("7. ",expression(bar(x))," =
> ",substitute(meanx,list(meanx=meanx))))
> #chart 8:
>  hist(x,main=bquote("Heart Attack (" * bar(X)==.(meanx) *")"))
> 
> 
> 
> what i want to do is to show a title that says X Bar = mean, where Bar X is
> the mathematical notation for the mean X with a bar on top and mean is the
> mean value
> 
> the first 2 charts on top work using bquote() or substitute(), but they
> write the word 'mean' instead of X bar. The third one shows the X Bar with
> no value (it was a first attempt and I never included the value)
> 
> charts 4 and 5 and 6 attempt to incorporate either bquote() or substitute
> into #3 to make it work, in both cases it seems the bquote or the substitute
> is not properly being evaluated. In 6 and 7 specifically I put the
> expression inside the bquote or paste to see if reversing would work,
> finally 8 is the one suggested with slight modifications to replace round
> and mean for the variable with that result. (the output I get is attached)
> 
> I am hoping that someone can help me understand what I am doing wrong, and I
> guess how the nested functions are being evaluated. I am learning to use R,
> and while I may really never need to use math notation (in fact in my work I
> may confuse people more with X bar than using mean), I believe there is
> value to learning how to use the functions, I can see how they would be
> useful for writing code.functions that write code so one can dynamically
> solve problems. I have done that in SAS and I may do it in R
> 
> I appreciate anyones help. Sorry for the long post, but I wanted to show my
> process to solve and learn what is going on
> 
> Mario
> 
> 
> sample.png <http://r.789695.n4.nabble.com/file/n4650645/sample.png>
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/characters-mathematical-
> expressions-and-computed-values-tp4645916p4650645.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.




More information about the R-help mailing list