Dear R members, I have a quite large of function that are named like that f11,f12,...f15 f21,f22,...f25 .. f51,f52,...f52 These are static (hard-coded) functions that the only common they have is that they take the same number and type of input fij(a,b,c,d). As you might understand this is really close to the notion of matrix only that my 'matrix' contains functions. It would be great if I can address all these function using a numbering-scheme like F(i,j) where for example F(1,1) will return the f11(a,b,c,d,). I am sure that this might be quite complex to implement so could you please refer me to some book/tutorial that addresses this kind of topics? I would like to thank you in advance for your help Best Regards Alex
Seems funny to me: > f <- list (mean, sd, median, sum) > dim (f) <- c (2, 2) or in one line: > f <- structure (.Data=list (mean, sd, median, sum), dim = c(2,2)) > f [,1] [,2] [1,] ? ? [2,] ? ? > f [1,1] [[1]] function (x, ...) UseMethod("mean") <environment: namespace:base> > f [[1,1]] (1:3) [1] 2 > f [[2,1]] (1:3) [1] 1 > f [[1,2]] (1:3) [1] 2 > f [[2,2]] (1:3) [1] 6 HTH Claudia On 02/03/2011 05:33 PM, Alaios wrote:> Dear R members, > I have a quite large of function that are named like that > f11,f12,...f15 > f21,f22,...f25 > .. > f51,f52,...f52 > > These are static (hard-coded) functions that the only common they have is that they take the same number and type of input fij(a,b,c,d). As you might understand this is really close to the notion of matrix only that my 'matrix' contains functions. It would be great if I can address all these function using a numbering-scheme like F(i,j) where for example > F(1,1) will return the f11(a,b,c,d,). > > I am sure that this might be quite complex to implement so could you please refer me to some book/tutorial that addresses this kind of topics? > > I would like to thank you in advance for your help > Best Regards > Alex > > ______________________________________________ > 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.-- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Universit? degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbeleites at units.it
Hello, Here is a quick suggestion: F<-function(i,j,a,b,c,d) { res<-eval(parse(text=paste("f",i,j,"(a,b,c,d),sep=""))) return(res) } HTH, Samuel -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios Sent: 03 February 2011 16:33 To: R-help at r-project.org Subject: [R] "Matrix' with Functions Dear R members, I have a quite large of function that are named like that f11,f12,...f15 f21,f22,...f25 .. f51,f52,...f52 These are static (hard-coded) functions that the only common they have is that they take the same number and type of input fij(a,b,c,d). As you might understand this is really close to the notion of matrix only that my 'matrix' contains functions. It would be great if I can address all these function using a numbering-scheme like F(i,j) where for example F(1,1) will return the f11(a,b,c,d,). I am sure that this might be quite complex to implement so could you please refer me to some book/tutorial that addresses this kind of topics? I would like to thank you in advance for your help Best Regards Alex ______________________________________________ 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. __________ Information from ESET NOD32 Antivirus, version of virus signature database 5843 (20110203) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __________ Information from ESET NOD32 Antivirus, version of virus signature database 5843 (20110203) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com