The input values (a and b) for my foo() function come from a expand.grid() call.
I was wondering how to loop over the rows of input data.frame such that at each round, one a and b from one row of input data.frame is used in foo() as a named list?
foo <- function(a, b) {
b-a
}
input <- rev(expand.grid(b=1:4,a=1:4))
# a b
#1 1 1 # at round one, `a = 1`, `b = 1`
#2 1 2
#3 1 3
#4 1 4 # at round four, `a = 1`, `b = 4`
#. . .
#. . .
#. . .
foo(a=, b=)
# Desired output:
[[1]] `a=1, b=1`
[1] 0
[[2]] `a=1, b=2`
[1] 1
# .
# .
# .
foo(input$a, input$b)and R will automatically do it for all rows and return a vector of the same length as a and b.listoutput?