0

Can anyone please help me to solve the error. I want to check in IF statement that, if there is no Null then insert the value.

 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
Gajanan Kulkarni
  • 697
  • 6
  • 22
Saara
  • 105
  • 12
  • A reproducible example (including e.g. `my_get()` function and some data) would be nice! – Adela Oct 23 '17 at 10:45
  • 1
    Growing vectors that way is not advised. `library()` calls inside a loop are not a good idea. If you know you need a conditional, where did you try putting it that didn't work? R has an `is.null()` function and you can also test for `length(thing) == 0`. – hrbrmstr Oct 23 '17 at 11:04
  • Thank you for your help :) – Saara Oct 23 '17 at 11:37

1 Answers1

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
   };
Saara
  • 105
  • 12