【问题标题】:Storing an object to a list and giving it a name stored in a character vector in R将对象存储到列表中并为其命名存储在 R 中的字符向量中
【发布时间】:2017-06-23 16:06:34
【问题描述】:

我正在运行 glm 分类器,我想将模型存储在一个命名列表中,为每个模型提供分类器中使用的预测器的名称——从字符向量中提取。但是我遇到了一个错误。

对于一个可重现的示例,我使用 mtcars 数据集(基础 R):

> data(mtcars)
> results <- list()
> model1 <- glm(am ~ hp, mtcars, family ="binomial")
> results <- list()
> names <- c("hp"  , "cyl")
> results <- append(results, list(names[1] = model1))
Error: unexpected '=' in "results <- append(results, list(names[1] ="

您的建议将不胜感激。

【问题讨论】:

    标签: r list model glm named


    【解决方案1】:

    将最后一行替换为

    results[[names[1]]] <- model1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多