在循环期间为模型构建指定不同的名称

时间:2018-06-07 12:19:35

标签: r regression models rda

我创建了多个模型并将它们存储在循环中的单独名称中

df <- data.frame(loc.id = rep(1000:1009,each = 20), y = rnorm(20*10), x = rnorm(20*10))

loc.vec <- c(1000:1009)

for(l in seq_along(loc.vec)){

      loc <- loc.vec[[l]]
      df.loc <- df[df$loc.id == loc,]
      mdl <- with(df.loc,lm(y ~ x))
      saveRDS(mdl,paste0("mod",loc,".mg.",".rda"))
      rm(mdl)
  }

当我尝试在循环中重新加载模型时:

  loc.vec <- c(1000:1009)

  for(l in seq_along(loc.vec)){

    loc <- loc.vec[[l]]
    readRDS(paste0("mod",loc,".mg.",".rda"))
  }

如何加载它们,使我的全局环境模型为mod.1000.mg,mod.1001.mg,mod.1002.mg等等

0 个答案:

没有答案