【问题标题】:Using loop index to give names and wild card symbols for cbind使用循环索引为 cbind 提供名称和通配符
【发布时间】:2018-01-08 16:55:26
【问题描述】:

我想运行一个循环,为每次循环迭代保存一个单独的结果元素。此元素应在名称中包含循环索引,以免被覆盖。

我的问题是,当元素应该被保存时,我不知道如何在元素名称中使用循环索引。

这是我想要运行的代码:

data.frame1 <- data.frame(x=c(1:10))

for (i in 1:5) {
  res.data.frame[i] <- data.frame1 * i


}

【问题讨论】:

    标签: r loops indexing wildcard


    【解决方案1】:

    我找到了使用assign函数的解决方案:

    data.frame1 <- data.frame(x=c(1:10))
    
    for (i in 1:5) {
      assign(paste("res.data.frame", i, sep = ""), data.frame1 * i)    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 2015-03-17
      • 2015-06-30
      • 1970-01-01
      相关资源
      最近更新 更多