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! 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.
Milan Bouchet-Valat
2012-Oct-20 11:37 UTC
[R] can't find the error in if function... maybe i'm blind?
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.
Jim Holtman
2012-Oct-20 11:39 UTC
[R] can't find the error in if function... maybe i'm blind?
Learn how to debug your programs. Start with options(error = recover) this will give you control at the point of the error so you can examine values. Most likely one of the variables in the 'if' expression is an NA. Sent from my iPad On Oct 20, 2012, at 6:27, Janosch <Janosch1985 at web.de> wrote:> 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! > > 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.