从多级列表中提取信息 - R.

时间:2015-03-05 20:30:48

标签: r list wildcard multi-level

我从写入多级列表的模型输出。本质上,有5个变量,并且构造列表以便每个场景的结果由该场景中的变量值标识。因此可以通过

访问K = 0.5,C = 0.9,V = 0.5,R = 0.25和RV = 0的运行结果
results$`K=0.05`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0`
1] FALSE FALSE FALSE FALSE FALSE

以下是完整输出的外观示例:

results
$`K=0.05`
$`K=0.05`$`C=0.9`
$`K=0.05`$`C=0.9`$`V=0.5`
$`K=0.05`$`C=0.9`$`V=0.5`$`R=0.25`
$`K=0.05`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.05`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.05`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE




$`K=0.05`$`C=0.91`
$`K=0.05`$`C=0.91`$`V=0.5`
$`K=0.05`$`C=0.91`$`V=0.5`$`R=0.25`
$`K=0.05`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.05`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.05`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE




$`K=0.05`$`C=0.92`
$`K=0.05`$`C=0.92`$`V=0.5`
$`K=0.05`$`C=0.92`$`V=0.5`$`R=0.25`
$`K=0.05`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.05`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.05`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE





$`K=0.1`
$`K=0.1`$`C=0.9`
$`K=0.1`$`C=0.9`$`V=0.5`
$`K=0.1`$`C=0.9`$`V=0.5`$`R=0.25`
$`K=0.1`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.1`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.1`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE




$`K=0.1`$`C=0.91`
$`K=0.1`$`C=0.91`$`V=0.5`
$`K=0.1`$`C=0.91`$`V=0.5`$`R=0.25`
$`K=0.1`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.1`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.1`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE




$`K=0.1`$`C=0.92`
$`K=0.1`$`C=0.92`$`V=0.5`
$`K=0.1`$`C=0.92`$`V=0.5`$`R=0.25`
$`K=0.1`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.1`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.1`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE





$`K=0.15`
$`K=0.15`$`C=0.9`
$`K=0.15`$`C=0.9`$`V=0.5`
$`K=0.15`$`C=0.9`$`V=0.5`$`R=0.25`
$`K=0.15`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.15`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE  TRUE FALSE FALSE FALSE

$`K=0.15`$`C=0.9`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE




$`K=0.15`$`C=0.91`
$`K=0.15`$`C=0.91`$`V=0.5`
$`K=0.15`$`C=0.91`$`V=0.5`$`R=0.25`
$`K=0.15`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.15`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.15`$`C=0.91`$`V=0.5`$`R=0.25`$`RV=0.1`
[1]  TRUE FALSE FALSE FALSE FALSE




$`K=0.15`$`C=0.92`
$`K=0.15`$`C=0.92`$`V=0.5`
$`K=0.15`$`C=0.92`$`V=0.5`$`R=0.25`
$`K=0.15`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0`
[1] FALSE FALSE  TRUE FALSE FALSE

$`K=0.15`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0.05`
[1] FALSE FALSE FALSE FALSE FALSE

$`K=0.15`$`C=0.92`$`V=0.5`$`R=0.25`$`RV=0.1`
[1] FALSE FALSE FALSE FALSE FALSE

对于分析,我希望能够从具有特定变量值的所有场景中提取结果。例如,我想提取C = 0.92和RV = 0.1(或任何组合,真的)的场景结果。

类似的东西:

results$*$'C=0.92'$*$*$'RV=0.1'

results[*]['C=0.92'][*][*]['RV=0.1']

我读了一个关于wildcards的类似问题,我认为R并没有使用它,但这并不是我需要它去的地方。有什么建议吗?

干杯!

1 个答案:

答案 0 :(得分:3)

您确实应该将数据存储在数据框架或其他类似的数据框架中。我知道当你在循环中运行测试时,递归结构很方便,但仍然如此。幸运的是,有一个功能可以进行翻译:

lst <- list(a=list(b=list(c0=list(d0=1:3, e0=4:6), c1=list(d1=7:9, e1=10:12))))
library(reshape2)
DF <- melt(lst)
subset(DF, grepl("1", L4))  # now we can use regular expressions against each list level

产地:

   value L4 L3 L2 L1
7      7 d1 c1  b  a
8      8 d1 c1  b  a
9      9 d1 c1  b  a
10    10 e1 c1  b  a
11    11 e1 c1  b  a
12    12 e1 c1  b  a

您可能需要查看DF以了解我正在对子集进行的操作。