我具有以下元素向量:
list_alg <- c("rf", "nnet", "knn", "rpart")
,我希望将其与以下命名列表相交:
list_tune <- list(
glmnet = caretModelSpec(method = "glmnet"),
svm = caretModelSpec(method = "svmRadial"),
rf = caretModelSpec(method = "rf", importance = TRUE),
nnet = caretModelSpec(method = "nnet"),
knn = caretModelSpec(method = "knn"),
rpart = caretModelSpec(method = "rpart")
)
我尝试了intersect(list_alg , list_tune)
的变体;但是,这将返回一个空列表。我的目标是创建包含list_alg
向量元素的列表;但是也会保留list_tune
的其他元素(请参见下面的示例输出)。
我试图实现的输出看起来像这样:
list(rf = list(method = "rf", importance = TRUE), nnet = list(
method = "nnet"), knn = list(method = "knn"), rpart = list(
method = "rpart"))
$`rf`
$`rf`$`method`
[1] "rf"
$`rf`$importance
[1] TRUE
$nnet
$nnet$`method`
[1] "nnet"
$knn
$knn$`method`
[1] "knn"
$rpart
$rpart$`method`
[1] "rpart"