用于NULL检查的If else语句出错

时间:2017-10-23 10:24:50

标签: r null-check

任何人都可以帮我解决错误。我想检查IF语句,如果没有Null则插入值。

 while (i < 33 )
{
 library(jsonlite)
 library(httr)
 get_reply2 <- my_get(staypoints$Stayplon[i],staypoints$staypLat[i], 2)
 get_replyFF2 <- append(get_replyFF2, get_reply2$value$id) 
 get_replyFG2 <- append(get_replyFG2, get_reply2$value$title) 
  if (get_replyFF2[i] != 0)
  {
  LONGG <- append(LONGG, staypoints$Stayplon[i])
  LATT <- append(LATT, staypoints$Stayplon[i])
  }

   i <- i + 1
 };

 Error: Error in if (get_replyFF2[i] != 0) { : 
 missing value where TRUE/FALSE needed

1 个答案:

答案 0 :(得分:0)

while (i < 33 )
{
 library(jsonlite)
 library(httr)
 get_reply2 <- my_get(staypoints$Stayplon[i],staypoints$staypLat[i], 2)
 get_replyFF2 <- append(get_replyFF2, get_reply2$value$id) 
 get_replyFG2 <- append(get_replyFG2, get_reply2$value$title) 
 if (length(get_reply2) != 0)
  {
  LONGG <- append(LONGG, staypoints$Stayplon[i])
  LATT <- append(LATT, staypoints$staypLat[i])
   }  

    i <- i + 1
   };