Create a grid of the desired values, subset it down to those needed and then Map
or mapply
over it or in (3) directly generate it.
v <- c(1, 1.1)
# either of these would be ok
g <- expand.grid(a = v, b = v, c = v)
# g <- do.call("expand.grid", Map(function(x) v, c("a", "b", "c")))
g <- g[rowSums(g != 1) == 1, ]
# either of these would be ok
transform(g, result = mapply("model", g$a, g$b, g$c))
# transform(g, result = do.call("mapply", c("model", g)))
giving:
a b c result
2 1.1 1.0 1.0 111.1
3 1.0 1.1 1.0 112.0
5 1.0 1.0 1.1 121.0
2) There are also a number of list comprehension packages (comprehenr, eList, listcompr) that can be used:
library(listcompr)
gen.data.frame(data.frame(a, b, c, result = model(a, b, c)),
a = v, b = v, c = v, (a != 1) + (b != 1) + (c != 1) == 1)
giving:
a b c result
1 1.1 1.0 1.0 111.1
2 1.0 1.1 1.0 112.0
3 1.0 1.0 1.1 121.0
3) diag We can directly create the g matrix using diag
:
g <- diag(.1, 3) + 1
colnames(g) <- c("a", "b", "c")
cbind(g, result = apply(g, 1, function(x) model(x[1], x[2], x[3])))
giving this matrix:
a b c result
[1,] 1.1 1.0 1.0 111.1
[2,] 1.0 1.1 1.0 112.0
[3,] 1.0 1.0 1.1 121.0