Re: [R] filling array with functions

From: Richard M. Heiberger <rmh_at_temple.edu>
Date: Sun, 24 Apr 2011 17:38:06 -0400

Derek,

You need a list.

f1 <- function(x) sin(x)
f2 <- function(x) cos(x)
f.list <- list(f1, f2)

f.list[[1]](pi)
f.list[[2]](pi)
## Note the double '[[' indexing.

## You can dimension a list to allow multiple-index indexing. dim(f.list) <- c(2,1)
f.list[[1,1]](pi)
Rich

On Sun, Apr 24, 2011 at 9:37 AM, derek <jan.kacaba_at_gmail.com> wrote:

> Thats not exactly what I hoped for. But for now it has to suffice. More
> transparent syntax would be nicer.
>
> Exactly what I would like to do is:
>
> for (i in 1:9){
> f[i]<-function(x){
> a*x+b)
> }
> curve(f[i], 0, 8)
> sol[i]<-uniroot(f[i],c(0, 8))$root
> points(sol[i],0,pch=16,cex=1,col="red")
> }
>
> Perhaps is item for a wish list?
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3471463.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Sun 24 Apr 2011 - 21:40:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 25 Apr 2011 - 11:10:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive