[R] defining a function using strings

Rolf Turner r.turner at auckland.ac.nz
Thu Oct 16 21:32:46 CEST 2008


On 17/10/2008, at 7:40 AM, Chernomoretz Ariel wrote:

> Hi All,
> I need to evaluate a series expansion using Legendre polynomials.
> Using the 'orthopolinom' package I can get a list of the first n
> Legendre polynomials as character strings.
>
>> library(orthopolynom)
>> l<-legendre.polynomials(4)
>> l
> [[1]]
> 1
>
> [[2]]
> x
>
> [[3]]
> -0.5 + 1.5*x^2
>
> [[4]]
> -1.5*x + 2.5*x^3
>
> [[5]]
> 0.375 - 3.75*x^2 + 4.375*x^4
>
> But I can't figure out how to implement functions that could be
> evaluated for arbitrary 'x', from this list,
> Thanks for your help.

?as.function
methods(as.function)
?as.function.polynomial
foo <- as.function(l[[4]])
foo(3)

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}



More information about the R-help mailing list