【问题标题】:Argument is of length zero in if statement using R在使用 R 的 if 语句中,参数的长度为零
【发布时间】:2014-09-08 13:30:35
【问题描述】:

有谁知道我该如何解决这个问题?

for (x in 1:nrow(homer1)-1) {if ((homer1$Start [x+1] +1) == homer1$End [x]) {homer1$annnot_prom <- paste(homer1$Detailed.Annotation, homer1$Nearest.PromoterID, sep="_") } else {homer1$annnot_prom <- homer1$Detailed.Annotation} }

Error in if ((homer1$Start[x + 1] + 1) == homer1$End[x]) { : 
  argument is of length zero

【问题讨论】:

  • 被比较的一个或两个值可能是 NA 。几乎可以肯定是由于运算符优先级规则。试试for(x in 1:(nrow(homer1)-1)
  • 学习help("Syntax").

标签: r


【解决方案1】:

for 循环中添加一些括号:

for (x in 1:(nrow(homer1)-1))

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多