javed khan
2022-Jan-26 13:47 UTC
[R] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
I get this error: Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed I used this: var <- ifelse(test$operator == 'T14', 1, 0) operator has several values like T1, T3, T7, T15, T31, T37 For some values like T3, T7 it works fine but for majority of values it gives error. When I use: is.na(ts$operator), it shows all false values so no NAs. Where could be the problem? [[alternative HTML version deleted]]
Ivan Krylov
2022-Jan-26 13:53 UTC
[R] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
On Wed, 26 Jan 2022 14:47:16 +0100 javed khan <javedbtk111 at gmail.com> wrote:> Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed> var <- ifelse(test$operator == 'T14', 1, 0)The error must be in a place different from your test$operator comparison. Have you tried traceback() to get the call stack leading to the error? Or options(error = recover) to land in a debugger session the moment an uncaught error happens? (Use options(error = NULL) to go back to the default behaviour.) Unrelated: var <- test$operator == 'T14' will also give you an equivalent logical vector with a bit less work. -- Best regards, Ivan
PIKAL Petr
2022-Jan-26 14:01 UTC
[R] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
Hi Do not post in HTML, please. Try to show your real data - use str(test), or preferably dput(test). If test is big, use only fraction of it The problem must be probably in your data. x <- sample(1:20, 100, replace=T) fake <- paste("T", x, sep="") ifelse(fake=="T14", 1,0) [1] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 head(fake) [1] "T7" "T9" "T3" "T9" "T12" "T9"> str(fake)chr [1:100] "T7" "T9" "T3" "T9" "T12" "T9" "T19" "T19" "T12" "T2" "T17" ...>Cheers Petr> -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of javed khan > Sent: Wednesday, January 26, 2022 2:47 PM > To: R-help <r-help at r-project.org> > Subject: [R] Error in if (fraction <= 1) { : missing value whereTRUE/FALSE> needed > > I get this error: > > Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed > > I used this: > > var <- ifelse(test$operator == 'T14', 1, 0) > > operator has several values like T1, T3, T7, T15, T31, T37 > > For some values like T3, T7 it works fine but for majority of values itgives error.> > When I use: is.na(ts$operator), it shows all false values so no NAs. > > Where could be the problem? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Jeff Newmiller
2022-Jan-26 15:03 UTC
[R] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
Your error and your code don't match. Please spend some time to make a small reproducible example [1][2] when posting a question... you may even figure out your own answer before you send it out. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [2] http://adv-r.had.co.nz/Reproducibility.html On January 26, 2022 5:47:16 AM PST, javed khan <javedbtk111 at gmail.com> wrote:>I get this error: > >Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed > >I used this: > >var <- ifelse(test$operator == 'T14', 1, 0) > >operator has several values like T1, T3, T7, T15, T31, T37 > >For some values like T3, T7 it works fine but for majority of values it >gives error. > >When I use: is.na(ts$operator), it shows all false values so no NAs. > >Where could be the problem? > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.-- Sent from my phone. Please excuse my brevity.