【发布时间】:2019-11-12 01:15:52
【问题描述】:
第一次在这里发帖,对 R 来说是新手。我希望我做得对。
如何使用 R 以另一列行的值(仅值)填充新列,条件是第三列行的值。
谢谢!
【问题讨论】:
第一次在这里发帖,对 R 来说是新手。我希望我做得对。
如何使用 R 以另一列行的值(仅值)填充新列,条件是第三列行的值。
谢谢!
【问题讨论】:
你想要这样的东西吗:
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
}
}
【讨论】: