Suppose I have a data frame with columns named "foo" and "bar"
mydata <- data.frame(foo=rnorm(100), bar=rnorm(100))
and suppose I have a special scalar function that expects scalar inputs "x" and "y" and produces scalar output, for example
myfunction <- function(x, y) { if (x>0) y else x }
How to apply myfunction to every line of mydata with x being foo and y being bar?
Yes, I know that this particular example is ridiculously simple and can be very easily done in R, but I'm interested in the template. Imagine myfunction is very complex, and myfunction variable names should map to mydata column names. What is the general solution?
source share