R:从嵌套列表中删除具有NaN的所有元素

问题描述 投票:0回答:1

我有10000个我已经运行过的零膨胀GLMM的引导程序副本。这些重复项与原始系数一起存储在嵌套列表中。下面提供了一个示例:

dput(list)
list(base_coef_se = list(cond = structure(c(-1.09253995524795, 
0.0256301422371279, -1.0514969957993, 0.0240016805158904, 1.26641445088249, 
0.0802593307154245, 1.14126003018684, 0.146680139556809), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error"))), zi = structure(c(25.2015013459079, 
-1.21859733549644, 3.15690182258876, 1.19362141506194, 9.94706364916293, 
0.596529488331926, 1.43549374516962, 0.607416307342548), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error")))), resampled_coef_se = list(list(
cond = structure(c(34.9970753775844, -3.22572702513505, 17.6083767770097, 
3.37168668591985, NaN, NaN, NaN, NaN), .Dim = c(4L, 2L), .Dimnames = list(
    c("(Intercept)", "time", "post", "time_post"), c("Estimate", 
    "Std. Error"))), zi = structure(c(15.483714547828, -1.14317285084705, 
7.58752561192794, 1.20363485559809, NaN, NaN, NaN, NaN), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error")))), list(cond = structure(c(-146.774067639717, 
8.59851543039287, 38.8577512736417, -11.7226307624509, NaN, NaN, 
NaN, NaN), .Dim = c(4L, 2L), .Dimnames = list(c("(Intercept)", 
"time", "post", "time_post"), c("Estimate", "Std. Error"))), 
zi = structure(c(393.317183996712, -21.6891746824488, 222.051124261625, 
5.87025753585696, NaN, NaN, NaN, NaN), .Dim = c(4L, 2L), .Dimnames = list(
    c("(Intercept)", "time", "post", "time_post"), c("Estimate", 
    "Std. Error")))), list(cond = structure(c(42.2533620535011, 
-3.88611818057324, 22.4372206185289, 3.89030675595149, 29.2145236893512, 
2.65367313256613, 15.9311367067903, 2.65587575460308), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error"))), zi = structure(c(17.3647617397122, 
-1.34546016337903, 8.92430250655081, 1.36567882369832, 18.0255311579065, 
1.6716117456611, 10.5672462617773, 1.67614789060036), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error")))), list(cond = structure(c(-0.354897448197829, 
-0.0156398488462341, -1.04000607663322, 0.0754410074961221, 1.24513610433428, 
0.0787118964442171, 1.08966548000492, 0.140265121142117), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error"))), zi = structure(c(29.968034826095, 
-1.47628698180743, 2.96062386998035, 1.42736287027326, 12.6522852015015, 
0.758468697999968, 1.2969778116713, 0.762197527722121), .Dim = c(4L, 
2L), .Dimnames = list(c("(Intercept)", "time", "post", "time_post"
), c("Estimate", "Std. Error")))), list(cond = structure(c(-1.12374888354427, 
0.0274118172476898, 82.1775449647119, -83.6936071877345, NaN, 
NaN, NaN, NaN), .Dim = c(4L, 2L), .Dimnames = list(c("(Intercept)", 
"time", "post", "time_post"), c("Estimate", "Std. Error"))), 
zi = structure(c(25.6107080693792, -1.22260968583176, -86.6358416736526, 
91.338132285808, NaN, NaN, NaN, NaN), .Dim = c(4L, 2L), .Dimnames = list(
    c("(Intercept)", "time", "post", "time_post"), c("Estimate", 
    "Std. Error"))))))

许多副本未能收敛,需要再次运行。

问题

我如何用NaN索引没有这些元素的列表?也就是说,如何从列表中删除所有带有NaN的元素,从而仅保留元素$base_coef_se$resampled_coef_se[[3]]$resampled_coef_se[[4]]

[请注意,我不希望delete only the NaN或值为NaN的特定行。

r list
1个回答
0
投票

您可以在Filter中使用lapply

© www.soinside.com 2019 - 2024. All rights reserved.