Friday, 15 August 2014

Create function names using paste() in R -



Create function names using paste() in R -

this question has reply here:

what ways there edit function in r? 5 answers creating look tree in r 2 answers

i following

x = matrix(0, nrow = p, ncol = n) p=5 n=100 (i in 1:n) { x[1,i] = e1(t[i]) x[2,i] = e2(t[i]) x[3,i] = e3(t[i]) x[4,i] = e4(t[i]) x[5,i] = e5(t[i]) }

where e1(). e2(), e3(), e4() , e5() specific functions.

i have tried next code:

for(j in 1:p) { (i in 1:n) { x[j,i] = as.symbol(paste("e", j, sep = ""))(t[i]) } }

but not work.

thanks help

carole

one way utilize do.call :

r> myfun <- function(x) print(x) r> do.call(paste0("my","fun"), list("foo")) [1] "foo"

the first argument of do.call name of function (you can utilize paste here), , sec 1 list of arguments pass.

r function

No comments:

Post a Comment