[R] Vector of functions

Thomas Stibor thomas.stibor at in.tum.de
Sat Jul 2 18:36:42 CEST 2011


Hi there,

I have a vector of some functions e.g.
#-----------------------------#
f.1 <- function(a) {
  return( a );
}
f.2 <- function(a) {
  return( 1 - (tanh(a))^2 );
}
f.3 <- function(a) {
  return( 1 / (1+exp(-a)) * (1 - (1 / (1+exp(-a)))) );
}

func.l <- c(f.1, f.2, f.3); 
#-----------------------------#

and would like to calculate the output value of a function in the
vector, that is, pick e.g. function at position 2 in func.l and calculate the
output value for a=42.

func.l[2](42); # gives error

f <- func.l[2];
f(42); # gives error

Is there an easy way to solve this problem?

Cheers,
 Thomas



More information about the R-help mailing list