且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何根据R中的条件添加列

更新时间:2021-12-25 02:22:10

你应该使用 ifelse

transform(data1,
          mutation = ifelse (genotype == "B3",  "wt",
          ifelse (genotype %in% c("ein9","ein194"),
                  "phyB", "hy2")))

#      internode_length treatment genotype mutation
# 1           98.165       sun       B3       wt
# 2          116.633       sun       B3       wt
# 3          103.474       sun     ein9     phyB
# 4          120.683       sun       B3       wt
# 5          109.128       sun   ein194     phyB
# 6          129.076       sun       A2      hy2