[R] can't find the error in if function... maybe i'm blind?

Milan Bouchet-Valat nalimilan at club.fr
Sat Oct 20 13:37:26 CEST 2012


Le samedi 20 octobre 2012 à 03:27 -0700, Janosch a écrit :
> Hi everybody,
> 
> the following alway gives me the error
>  "Fehler in if (File$X.Frame.Number[a] + 1 == File$X.Frame.Number[a + 1])
> (File$FishNr[a] <- File$FishNr[a -  :   Fehlender Wert, wo TRUE/FALSE nötig
> ist". Maybe its stupid, but i'm not getting why... Maybe someone can help
> me.  Thanks a lot!
You could have told us what this error means in English, but my guess is
that File$X.Frame.Number[a] or File$X.Frame.Number[a + 1] is NA, which
means that the whole expression evaluates to NA, which is not corrrect
for if(). If you want NAs to be considered as FALSE, than put the
expression inside a isTRUE() call. If NAs are not expected there in your
code, there's a problem elsewhere.

Since the loop stops when the error is raised, "a" still contains the
value that produced it and you can easily check where the problem comes
from that way.


My two cents

> for (i in unique(BigFile$TrackAll))
>       { File <-  subset(BigFile,BigFile$TrackAll == i)
>          File$FishNr [1]  <- 1
>           for ( a in File$X.Frame.Number)
>                {if(File$X.Frame.Number[a]+1==  File$X.Frame.Number[a+1])
>                 (File$FishNr [a] <- File$FishNr[a-1])
>                 else(if (File$X.Frame.Number[a]+1 !=
> File$X.Frame.Number[a+1])
>                       (File$FishNr [a] <- File$FishNr[a-1]+1   ))
>            }
>        }
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/can-t-find-the-error-in-if-function-maybe-i-m-blind-tp4646839.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list