I am using R purrr:::pmap
with three inputs. It is not clear how I can refer explicitly to these inputs in the formula call? When using map2, the formula call goes as ~ .x + .y
. But how to do when using pmap
?
Reproducing Hadley's example from http://r4ds.had.co.nz/lists.html
library(purrr)
mu <- list(5, 10, -3)
sigma <- list(1, 5, 10)
n <- list(1, 3, 5)
args2 <- list(mean = mu, sd = sigma, n = n)
pmap(args2, rnorm)
If I want to refer explicitly to the input arguments when calling rnorm
, I can use:
pmap(args2, function(mean, sd, n) rnorm(n, mean, sd))
But say I want to do this with the formula approach. How do I do that? This for example does not work:
pmap(args2, ~rnorm(n=.n, mean=.mean, sd=.sd))
Thanks!!