[R] Problem with 'expression'

Tamas Papp tpapp at axelero.hu
Tue May 11 17:13:24 CEST 2004


On Tue, May 11, 2004 at 04:31:21PM +0200, Perez Martin, Agustin wrote:

> For example:
> 
> 	a<-expression(exp(-x^2))
> 	b<-expression(exp(x^2))
> 
> And I want to calculate:
> 
> 	a*b

Use

t<-2
expression(a, list(x=t))*expression(b, list(x=t))

I am not sure what you are using these for, but maybe you could also
use functions --- more convenient for calculations.  Eg

a <- function(x) { exp(-x^2) }
b <- function(x) { exp(x^2) }
a(x)*b(x) # =1

For evaluating the same functions many times, see ?sapply and the
related pages.

Best,

Tamas

-- 
Tamás K. Papp
E-mail: tpapp at axelero.hu
Please try to send only (latin-2) plain text, not HTML or other garbage.




More information about the R-help mailing list