首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >否则If语句

否则If语句
EN

Stack Overflow用户
提问于 2013-10-28 22:22:18
回答 1查看 263关注 0票数 1

我正在R中运行以下内容:

代码语言:javascript
复制
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 <- ""
}

这让我犯了每个人似乎都会犯的错误:

代码语言:javascript
复制
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

我假设这与单个值与向量有关(前者,我想这样做)。我是否需要事先指定数据框架?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-28 22:47:14

ifelse()就是在这种情况下工作的:

代码语言:javascript
复制
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',
                                   ''))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19646158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档