【发布时间】:2014-10-10 02:10:19
【问题描述】:
我有这样的 df(data1)
internode_length treatment genotype
1 98.165 sun B3
2 116.633 sun B3
3 103.474 sun B3
4 120.683 sun B3
5 109.128 sun B3
6 129.076 sun B3
我想根据条件向这个df添加一个单独的列
for i in (1:nrow(data1)){
if (data1$genotype == "B3") {
data1$mutation = "wt"
} else if (data1$genotype == "ein9" & "ein194"){
data1$mutation = "phyB"
} else {
data1$mutation = "hy2"
}
}
但是我收到了这个错误和警告,而且它也不起作用
Error: unexpected symbol in "for i"
> if (data1$genotype == "B3") {
+ data1$mutation = "wt"
+ } else if (data1$genotype == "ein9"){
+ data1$mutation = "phyB"
+ } else {
+ data1$mutation = "hy2"
+ }
Warning message:
In if (data1$genotype == "B3") { :
the condition has length > 1 and only the first element will be used
> }
Error: unexpected '}' in "}"
有解决此问题的建议吗?
【问题讨论】:
标签: r loops if-statement