简体   繁体   中英

using map2 and map/lapply over 3 objects in R

I am trying to map two lists over myEq with a third numeric input which is not the same length as mus and Sigmas .

The equation I want to map over:

library(CVXR)
myEq <- function(mu, Sigma, lmd) {
  w <- Variable(nrow(Sigma))
  prob <- Problem(Maximize(t(mu) %*% w - lmd*quad_form(w, Sigma)),
                  constraints = list(w >= 0, sum(w) == 1))
  result <- solve(prob)
  return(as.vector(result$getValue(w)))
}

The lmd values I want to use for the 2 lists mus and Sigmas

lmd = c(0.2, 0.5)

My current attempt

map2(.x  = mus,
     .y = Sigmas,
     map(lmd, ~myEq))

I get this error:

Error in nrow(Sigma) : argument "Sigma" is missing, with no default

I have tried using lapply when replacing map

Data:

mus <- list(structure(c(-0.00255206467736065, 0.00132338514890967), .Dim = 1:2, .Dimnames = list(
    NULL, c("var1", "var2")), index = structure(1362190829.26829, tzone = "UTC", tclass = "Date"), class = c("xts", 
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00000383546990064197, 0.00519015561557173), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1364878496.38554, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00119765261936219, 0.00587874140404111), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1367310857.14286, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000333130040172382, 0.00454629816615796), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1369938306.97674, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00126536481963645, 0.00172154767394349), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1372658902.32558, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000772926784253394, -0.000579347285491438), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1375285371.42857, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00325100104730687, -0.00230030093594783), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1377945931.03448, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.0025699116858321, -0.000412839056603177), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1380519529.41176, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00174835859070294, 0.00200553002538724), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1383189942.85714, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000642781942241883, -0.00123610503483248), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1385769600, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000228873537085742, 0.00129705024235475), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1388442666.66667, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.000358688977176841, 0.00118057999597352), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1391073717.07317, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000688855732683294, 0.000674273939183168), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1393743687.80488, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00300244946960844, 0.00187480609685417), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1396369404.87805, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00259011019764845, 0.00144843877755598), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1398864342.85714, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00266046026827614, -0.000297104321425926), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1401553355.29412, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00242387365310797, 0.000227894891247046), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1404169750.58824, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00132992687990261, -0.00187743611558195), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1406796310.58824, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00178444071207707, -0.00463311858336654), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1409516689.65517, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.0027101281002697, -0.00401780688290477), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1412031085.71429, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000922273344726573, -0.00524514780468885), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1414701402.35294, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.001847917034708, -0.00336674276652734), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1417278857.14286, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00227190278973034, 0.00131254136262481), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1419954840, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000592132783777474, -0.000484636160367575), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1422584327.71084, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00157954727004818, -0.00203309340399955), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1425333424.39024, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00139332522119638, -0.00146012751147292), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1427833756.09756, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00023178286507715, -0.00304887045690874), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1430390625.88235, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.000250683287027295, -0.00386231519536437), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1433141195.29412, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00112431357017612, -0.0026122113883113), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1435744376.47059, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00188332333403477, -0.00327733897838358), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1438300800, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.000510640887799796, -0.00144247265895324), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1441021395.34884, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.000193516179069833, 0.00239454304905624), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1443598971.42857, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.000759492926669591, 0.00542335511169171), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1446266880, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00145449128449705, 0.00296545866914348), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1448788510.84337, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00249534969905046, 0.000115922720368385), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1451467733.33333, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00092236471388936, 0.00227298042461495), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1454164048.19277, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.00134752502566396, 0.00259311675263164), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1456915785.36585, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00044096453363128, 0.00870304576835527), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1459410171.42857, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.0000612479401202943, 0.0101889215166664), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1462024632.55814, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(-0.000461640813717664, 0.0104570053268718), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1464644571.42857, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00157360186884271, 0.00854107438049767), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1467370381.39535, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00150538967914637, 0.00480763294038913), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1469992520.93023, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00208688008442689, 0.00401395243180706), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1472655472.94118, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000805952717675603, 0.00304031162494097), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1475173506.97674, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00110447850191852, 0.00508162259630336), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1477899771.42857, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.000915296948778974, 0.00489093234291394), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1480487942.16867, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00243457182611089, 0.00855737259950549), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1483031466.66667, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00321179747027812, 0.00590863556788896), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1485845783.13253, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.00271195992996765, 0.00196824366577903), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1488397866.66667, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"), 
    structure(c(0.0028751151888175, 0.000916909639546961), .Dim = 1:2, .Dimnames = list(
        NULL, c("var1", "var2")), index = structure(1491017291.56626, tzone = "UTC", tclass = "Date"), class = c("xts", 
    "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC"))



Sigmas <- list(structure(c(0.000416643886758763, 0.0000575201746765611, 
0.0000575201746765611, 0.00119570936132192), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000266376810665656, 
0.000102646024469171, 0.000102646024469171, 0.00132219539700646
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000260185752934072, 0.000103619179723936, 
0.000103619179723936, 0.0012673944241585), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000292123566686645, 
0.0000969406988711502, 0.0000969406988711502, 0.00127398532527367
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000239845257172422, 0.0000430979663815108, 
0.0000430979663815108, 0.00131183305071473), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000230279463157106, 
0.0000739874936861984, 0.0000739874936861984, 0.000910358217087931
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000230110063541892, 0.0000673718024935079, 
0.0000673718024935079, 0.000860281827885971), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000275136657760233, 
0.0000243010954971029, 0.0000243010954971029, 0.000724892729666947
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000257619135102119, 0.0000104445983502885, 
0.0000104445983502885, 0.000711519783478368), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000184581216637241, 
0.0000133677603492306, 0.0000133677603492306, 0.000699854456313018
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000235147061618121, 0.0000398013791560585, 
0.0000398013791560585, 0.000632228300936625), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.00022619770686518, 
0.0000375478992263042, 0.0000375478992263042, 0.000624839092129104
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000211462307066135, 0.0000551275926865566, 
0.0000551275926865566, 0.000676047929515918), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000147949303256583, 
0.0000399568063514618, 0.0000399568063514618, 0.000758909616965475
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000134630670602486, 0.0000302650092572614, 
0.0000302650092572614, 0.00072540753779361), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000175939364486961, 
0.0000331323908196066, 0.0000331323908196066, 0.000693994712946441
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000129212272966643, 0.0000415228097821573, 
0.0000415228097821573, 0.000692391186802157), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000130766308753806, 
0.0000351333325425634, 0.0000351333325425634, 0.000707098827657046
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000163414496290672, 0.0000478611442445727, 
0.0000478611442445727, 0.000687693433879279), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000227240912818136, 
0.000055642807484727, 0.000055642807484727, 0.00057330158082961
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000249467759867583, 0.0000732080874629842, 
0.0000732080874629842, 0.000853091135055051), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000232311819250863, 
0.0000870888332896381, 0.0000870888332896381, 0.000887692782681684
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000234674585046656, 0.0000773880049326534, 
0.0000773880049326534, 0.000872461228088176), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000249582257901038, 
0.0000844920557837083, 0.0000844920557837083, 0.000863038684277783
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000213142060855619, 0.0000639375852287925, 
0.0000639375852287925, 0.000886176461175403), .Dim = c(2L, 2L
), .Dimnames = list(c("var1", "var2"), c("var1", "var2"))), structure(c(0.000165564225200343, 
0.0000845126933563584, 0.0000845126933563584, 0.00117906832322701
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.00025713436292721, 0.0000380748427609064, 
0.0000380748427609064, 0.00121309361549552), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000296845726988689, 
0.0000722563482858919, 0.0000722563482858919, 0.00138510790746498
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000316490596607412, 0.0000893980268140116, 
0.0000893980268140116, 0.00130931898484327), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000318703164134305, 
0.000121709689640438, 0.000121709689640438, 0.00141796813960752
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000351883461491064, 0.000151196103623349, 
0.000151196103623349, 0.00154094433668585), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.00043069121566456, 
0.000200635409747552, 0.000200635409747552, 0.00172757406078867
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000343563969695955, 0.000267969632111019, 
0.000267969632111019, 0.00154770002949457), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000301055050473832, 
0.000228988620454581, 0.000228988620454581, 0.00173596297383636
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000315586351653507, 0.000223990676994839, 
0.000223990676994839, 0.00338347000341234), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000310266260483569, 
0.000197636020585792, 0.000197636020585792, 0.00332385949427085
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000290416024396974, 0.000188770207606681, 
0.000188770207606681, 0.00353454914604761), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000217155182285281, 
0.000101664407489019, 0.000101664407489019, 0.00313462005559849
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000191050545037883, 0.0000676440775611981, 
0.0000676440775611981, 0.00305357636754232), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000208688934754722, 
0.0000905556333743095, 0.0000905556333743095, 0.00288974215821908
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000155902045107429, 0.000093770380151406, 
0.000093770380151406, 0.00140221905810905), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.00015741462693176, 
0.000135297517294262, 0.000135297517294262, 0.00161401551126313
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000143442962212522, 0.0001171571099816, 
0.0001171571099816, 0.00141905619957792), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000107816456252584, 
0.00013966971407248, 0.00013966971407248, 0.00121132578010688
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000129954453011776, 0.000203619382720884, 
0.000203619382720884, 0.00147438699298417), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.0000946849200985651, 
0.000184791369482893, 0.000184791369482893, 0.00141240016838301
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.0000907201232739304, 0.000174949733476451, 
0.000174949733476451, 0.00135256580855926), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.0000852212445727315, 
0.000142920898530822, 0.000142920898530822, 0.00194747500479968
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))), structure(c(0.000114991493081128, 0.000163871786225392, 
0.000163871786225392, 0.00198318050704355), .Dim = c(2L, 2L), .Dimnames = list(
    c("var1", "var2"), c("var1", "var2"))), structure(c(0.000120400816763184, 
0.000180475331817304, 0.000180475331817304, 0.00203894796554627
), .Dim = c(2L, 2L), .Dimnames = list(c("var1", "var2"), c("var1", 
"var2"))))

I think what you need to do is first convert mus to numeric and then for every value in lmd run myEq in map2 .

library(purrr)
mus <- map(mus, as.numeric)
map(lmd, ~map2(mus, Sigmas, myEq, lmd = .x))


#[1]]
#[[1]][[1]]
#[1] 0.00000000937 0.99999999063

#[[1]][[2]]
#[1] 0.000000091 0.999999909

#[[1]][[3]]
#[1] 0.0000000779 0.9999999221

#[[1]][[4]]
#[1] 0.0000000351 0.9999999649

#[[1]][[5]]
#[1] 0.0875 0.9125
#...
#...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM