[R] math expressions

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Jan 19 23:58:26 CET 2001


Don Wingate wrote:
> 
> Dear Uwe (and All R users),
> 
> The problem is that the vector of names I want to use is created dynamically
> at a time independent of the plotting. The situation is a bit complex. An
> object is created, say "object.to.plot" which has as an attribute the vector
> of names, say "labels.names". This vector of names is created dynamically
> according to parameter values present when "object.to.plot" is created
> (using the string manipulating functions, especially paste). When using
> dotplot on the values associated with this object, I can easily use the
> names vector for labels. What I want to do is create a vector of math
> expressions, based on the names vector. Do you think there is a way to do
> this?
> 
> More generally, what I need to do is dynamically create a vector of math
> expressions (using the powers of string manipulation), which can then be
> used as the textual values for a plot function.


What about something like:

   numbers <- 1:2  # the dynamical part
   my.names <- NULL
   for(i in numbers) 
      my.names <- c(my.names, 
         eval(as.expression(substitute(expression(x[i]^2), list(i=i)))))
   dotplot(1:2, labels = my.names)


I don't get it without a loop, but for a plot it shouldn't be too
expensive.

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list