【问题标题】:Replacing multiple cells (various row/column combinations) with one value in R data frame用R数据框中的一个值替换多个单元格(各种行/列组合)
【发布时间】:2016-12-14 17:07:58
【问题描述】:

有没有办法压缩下面的代码,在一行中列出

SchoolData[2,4]   <- Res.Stf0815[1,4]
SchoolData[3,5]   <- Res.Stf0815[1,4]
SchoolData[4,6]   <- Res.Stf0815[1,4]
SchoolData[5,7]   <- Res.Stf0815[1,4]

SchoolData[2,4], SchoolData[3,5], SchoolData[4,6], SchoolData[5,7] <- Res.Stf0815[1,4]

【问题讨论】:

    标签: r


    【解决方案1】:

    我们可以使用矩阵子集。

    SchoolData[cbind(2:5, 4:7)] <- Res.Stf0815[1,4]
    

    更多信息,see this answer

    【讨论】:

      猜你喜欢
      • 2016-06-05
      • 2020-09-06
      • 2019-05-16
      • 2016-01-03
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      相关资源
      最近更新 更多