【问题标题】:What is the way to create a new column based on a different column in R? [closed]基于 R 中的不同列创建新列的方法是什么? [关闭]
【发布时间】:2017-05-18 06:16:33
【问题描述】:
outcome_1  outcome_2
1               0
0               1
1               0
1               0
0               1
0               1
1               0
0               1

现有列是outcome_1。如何创建outcome_2

【问题讨论】:

  • as.numeric(!df$outcome_1).
  • df$outcome_2 <- (!df$outcome_1)+0

标签: r


【解决方案1】:

将变量outcome_2 构建为:

df$outcome_2 <- 1 - df$outcome_1

【讨论】:

  • 是的,正如@docendo discimus 编辑的那样,如果您在名为df 的data.frame 中有信息,这将是正确的方法。
猜你喜欢
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 1970-01-01
  • 2016-10-08
相关资源
最近更新 更多