[R] Applying function to multiple input vectors

Ronnen Levinson RML27 at cornell.edu
Mon Mar 28 01:38:37 CEST 2005


   Hi.
   Say I have a function f with two inputs, x and y

     f <- function(x,y) {something}

   that I wish to evaluate with two input vectors of length N

     X <- c(x1, x2, ..., xN)
     Y <- c(y1, y2, ..., yN)

   to  obtain  the  length-N  output  vector  c( f(x1,y1), f(x2,y2), ...,
   f(xN,yN) ).
   Is there a method analogous to sapply() for this operation?
   Yours truly,
   Ronnen.
   P.S. E-mailed CCs of posted replies appreciated.



More information about the R-help mailing list