On 9/6/07, Gustaf Rydevik <[EMAIL PROTECTED]> wrote:
> On 9/5/07, D. R. Evans <[EMAIL PROTECTED]> wrote:
> > D. R. Evans said the following at 09/04/2007 04:14 PM :
> > > I am 100% certain that there is an easy way to do this, but after
> >
> > I have reconsidered this and now believe it to be essentially impossible
> > (or at the very least remarkably difficult) although I don't understand why
> > it is so :-(
>
> How about:
>
> > foo<-c("a","b")
> > a<-1
> > b<-2
> > lapply(foo,function(x){eval(parse(text=paste(c("10+",x),collapse="")))})
> [[1]]
> [1] 11
>
> [[2]]
> [1] 12
>
>
> ,i.e you build up a text string containing your function call, and
> then evaluate it, once for each value of foo?
>
> /Gustaf
Applied to loess, it gives nice function names as well:
a<-rnorm(10)
> b<-rnorm(10)
> lapply(foo,function(x){eval(parse(text=paste(c("loess(y~",x,")"),collapse="")))})
[[1]]
Call:
loess(formula = y ~ a)
Number of Observations: 10
Equivalent Number of Parameters: 4.61
Residual Standard Error: 1.219
[[2]]
Call:
loess(formula = y ~ b)
Number of Observations: 10
Equivalent Number of Parameters: 4.45
Residual Standard Error: 1.433
--
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik
______________________________________________
[email protected] 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.