[英]Else If Statement
I'm running the following in R: 我在R中运行以下命令:
if (mito$count > 1) {
mito$Polymorphism <- "SNP"
} else if ((mito$count == 1) & (mito$A_GT == mito$ref | mito$C_GT == mito$ref | mito$G_GT == mito$ref | mito$T_GT == mito$ref)) {
mito$Polymorphism <- "No"
} else {
mito$Polymorphism <- ""
}
And its giving me the usual error that everyone seems to get: 它给了我每个人似乎都会遇到的常见错误:
1: In if (mito$count > 1) { :
the condition has length > 1 and only the first element will be used
2: In if ((mito$count == 1) & (mito$A_GT == mito$ref | mito$C_GT == :
the condition has length > 1 and only the first element will be used
I assume this has to do with single value vs a vector (the former, I want to do). 我认为这与单个值与向量有关(前者,我想这样做)。 Is there something I need to specify the data frame as beforehand?
我需要事先指定数据框吗?
ifelse()
worked in this situation: ifelse()
在这种情况下起作用:
mito$Polymorphism <- ifelse(mito$count > 1,
'SNP',
ifelse(((mito$count == 1) &
(mito$A_GT == mito$ref |
mito$C_GT == mito$ref |
mito$G_GT == mito$ref |
mito$T_GT == mito$ref)),
'NO',
''))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.