Re: [R] "Matrix' with Functions

2011-02-03 Thread Alaios
Dear all, I would like to thank you for your contribution. I think I got more that one good solutions to work on. Best Regards Alex --- On Thu, 2/3/11, Bert Gunter wrote: From: Bert Gunter Subject: Re: [R] "Matrix' with Functions To: "Samuel Le" Cc: "Alaios&quo

Re: [R] "Matrix' with Functions

2011-02-03 Thread Bert Gunter
There is no need for eval(parse...) As an another alternative to Rich Heiberger's suggestion, simply define your function as: F <- function(i,a,b,c,d) do.call(paste("f",i,sep=""), list(a,b,c,d)) -- Bert On Thu, Feb 3, 2011 at 9:22 AM, Samuel Le wrote: > Hello, > > Here is a quick suggestion:

Re: [R] "Matrix' with Functions

2011-02-03 Thread RICHARD M. HEIBERGER
This is very simple. Just put the functions in a list and make the list into a matrix. > f11 <- f12 <- f13 <- f21 <- f22 <- f23 <- function(x) x > F <- list(f11, f12, f13, f21, f22, f23) > F <- matrix(F, byrow=TRUE, 2, 3) > F[[1,1]](4) [1] 4 > Be careful that you get the rows and columns right wh

Re: [R] "Matrix' with Functions

2011-02-03 Thread Samuel Le
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: 03 Febru

Re: [R] "Matrix' with Functions

2011-02-03 Thread Claudia Beleites
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") > f [[1,1]] (1:3) [1] 2 > f [[2,1]] (1