Skip to content
Prev 198787 / 398506 Next

How to execute a funcition which name is stored in a string?

On Nov 1, 2009, at 11:07 PM, Ning Ma wrote:

            
Need to leave the "()" off.

 > fstr <- "sum"
 > eval(parse(text=fstr))(1:5)
[1] 15
> eval(parse(text="m1 <- matrix(1:9,3,3)"))
 > m1
      [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9