[R] Equation as a character string

2012-03-15 Thread Emily Weiser
I'm trying to figure out if it's possible to use a character string as an equation, e.g: eqn1string - x^2 + x + 5 Then I want to tell R: 1) that eqn1string is actually an equation (even though it was stored as a character string), and 2) to apply the equation to a specified value of x (e.g.

Re: [R] Equation as a character string

2012-03-15 Thread Joshua Wiley
Hi Emily, Yes (see below), but you might be better off by writing a simple function. Here are examples both ways (usually eval parse is highly discouraged). Cheers, Josh # eqn1string - x^2 + x + 5 x - 6 ## works eval(parse(text = eqn1string)) ## better f - function(x)

Re: [R] Equation as a character string

2012-03-15 Thread Rui Barradas
Hello, Hi Emily, Yes (see below), but you might be better off by writing a simple function. Here are examples both ways (usually eval parse is highly discouraged). Cheers, Josh Yes, eval/parse is discouraged but there's a way of using it, that is less troublesome, to create a

Re: [R] Equation as a character string

2012-03-15 Thread Gabor Grothendieck
On Thu, Mar 15, 2012 at 12:58 PM, Rui Barradas rui1...@sapo.pt wrote: Hello, Hi Emily, Yes (see below), but you might be better off by writing a simple function.  Here are examples both ways (usually eval parse is highly discouraged). Cheers, Josh Yes, eval/parse is discouraged but