I have some data stored in a list where I am trying to apply the following code to:
library(tidyverse)
library(purrr)
library(BVAR)
mins <- map(df1, ~ .x / 100)
maxs <- map(df1, ~ .x * 100)
So, now I have 3 lists and I want to use purrr
to pmap
a function over those lists:
The code I have is the following which does not work:
pmap(
list(
mode = df1,
min = mins,
max = maxs
# scale = 0.004,
# shape = 0.004
),
~bv_psi(..1, ..2, ..3)
)
The idea is to apply something like:
bv_psi(scale = 0.004, shape = 0.004, mode = df1, min = min, max = max)
Shape / Scale: 0.004 / 0.004
#1 Mode / Bounds: 0.0000000001 / [0.000000000001, 0.00000001]
#2 Mode / Bounds: 2.329554 / [0.02329554, 232.9554]
#3 Mode / Bounds: 0.3086792 / [0.003086792, 30.86792]
#4 Mode / Bounds: 0.289515 / [0.00289515, 28.9515]
#5 Mode / Bounds: 0.3444753 / [0.003444753, 34.44753]
But to all the columns.
Data:
df1 <- list(FRA = c(var1 = 0.348484926831081, var2 = 2.32955373143543,
var3 = 0.308679204532957, var4 = 0.242541092355223, var5 = 0.344475341669246
), ITA = c(var1 = 0.348484926831081, var2 = 2.26657313151514,
var3 = 0.34565008444245, var4 = 0.242541092355223, var5 = 0.403082188649582
), NOR = c(var2 = 1.20962811046986, var3 = 0.289000898298659,
var4 = 0.242541092355223, var5 = 0.34539772064608), SPA = c(var1 = 0.348484926831081,
var2 = 2.59042002848148, var3 = 0.748413615669766, var4 = 0.242541092355223,
var5 = 0.403082188649582), GER = c(var1 = 0.350388888258007,
var2 = 1.58267709209138, var3 = 0.230489915987761, var4 = 0.243815124309394,
var5 = 0.332742111113146))
You can use pmap
, with a names list in .l
(as you did), but with your scale
and shape
params in ...
pmap(list(mode=df1,min=mins,max=maxs),bv_psi, scale=0.004, shape=0.004)
Alternatively, you can use ~
style call to bv_psi
like these examples:
# Using default values for scale and shape
pmap(list(df1,mins,maxs), ~bv_psi(mode=..1, min=..2, max=..3))
# explicitly passing values for scale and shape
pmap(list(df1,mins,maxs), ~bv_psi(scale=0.001, shape=0.002,mode=..1, min=..2, max=..3))