【问题标题】:Populate a new column with the value of another column when the value of a third column当第三列的值时,用另一列的值填充新列
【发布时间】:2019-11-12 01:15:52
【问题描述】:

第一次在这里发帖,对 R 来说是新手。我希望我做得对。

如何使用 R 以另一列行的值(仅值)填充新列,条件是第三列行的值。

谢谢!

【问题讨论】:

    标签: r lapply summarize


    【解决方案1】:

    你想要这样的东西吗:

    for(i in 1:length(df$column1){        #runs the following code for each line
      if(df$thirdcolumn[i] > 0){              #if logical TRUE then it runs the next line
        df$newcolumn[i] <- df$anothercolumn[i]    #gives value of another column to a new column
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-24
      • 2019-01-21
      • 2020-08-31
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      相关资源
      最近更新 更多