I have two lists and a function, like this:
ms <- c(1, 2, 3)
ns <- c(4, 5)
f <- function(m, n) {
return result of some computation involving m and n
}
I want to get a table like this, where each entry is obtained by applying the function to each pair of elements in rows and cols:
4 5
-------------------
1 | f(1, 4) f(1, 5)
2 | f(2, 4) f(2, 5)
3 | f(3, 4) f(3, 5)
How do I do this? I don't want to use for
loops. I assume there is a way to do this using some form of apply
.