I am wondering how to use pmap()
function if I have more than 3 inputs as parameters to map into a function with other default inputs.
Here is a reproducible example:
a=c(5, 100, 900)
b=c(1, 2, 3)
ablist=list(mean=a,sd=b)
pmap(ablist, ~rnorm( mean=a , sd=b , n = 9))
outputs:
[[1]]
[1] 5.734723 99.883171 895.962561 5.346905 98.723191 903.373177 4.172267 96.424440 897.437970
[[2]]
[1] 4.427977 98.348139 899.287248 4.404674 99.178516 900.983974 3.836353 101.520355 899.992332
[[3]]
[1] 4.961772 95.927525 899.096313 4.444354 101.694591 904.172462 6.231246 97.773325 897.611838
But as you can see, the output is not mapping the mean
and sd
in the order of vectors.
I want to have [[1]]
with rnorm(mean=5,sd=1,n=9)
and so on. Out of curiosity, I am wondering what pmap()
is doing for this demo.
By the way, I know in this example, I can easily use map2()
without any hassle but in my real code, I have 10 inputs so I need to use pmap()
.
Thanks in advance for any replies!
pmap()
is very hard to understand though. Any suggests to learn it quickly? – Quintie