• Register
0 votes
521 views

Problem :

I have received below error message:

Error in if (condition) { : missing value where TRUE/FALSE needed

OR

Error in while (condition) { : missing value where TRUE/FALSE needed

What does it actually mean, and how can I fix this error?

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

 

Here the evaluation of the condition must have resulted in an NA. Any if condition must return either a TRUE or FALSE result as shown below :

if (NA) {}
## Error in if (NA) { : missing value where TRUE/FALSE needed

This can happen with anybody accidentally as the results of the calculations as shown below :

if(TRUE && sqrt(-1)) {}
## Error in if (TRUE && sqrt(-1)) { : missing value where TRUE/FALSE needed

 

Also to test whether any object is missing please use is.na(x) rather than the x == NA.

I also ran into this error in the recent past when I was trying to check on the null or empty string as shown below :

if (x == NULL || x == '') {

Then I did the lot of research on it and at the end of it I realized my mistake and I changed it as below:

if (is.null(x) || x == '') {

 

Hope it solves your issue.

9 7 4
38,600 points
0 votes

Solution:

Consider  having this same issue when trying to view a data set we imported. we could also view individual elements but not the whole data set. we solved it by converting it to a data frame using

as.data.frame(dataset)

R has a wierd (and super annoying) way of handling NAs. if your output is empty then nchar(output) will return integer(0). You can get around this by adding another if statement with if(length(nchar(output)) > 0){...}

I did tests with the function with far less observations, but also generating 0 obs in "Unique in SetY" And I had no problem viewing those lists

May be you forgot to update the "Save workspace to .Rdata upon exit" to Never. After that change, you re-started R-studio and the error message did not re-appear. 

Updating R and sp to the released versions will resolve this.

It was caused by a change in R's behavior on what nchar(NA) returns: see the help file of ?nchar, argument keepNA.

we think the issue might be your use of things like all$age7. we suspect that 'all' is the name of a data frame and you intend the mxMatrix named 'Age' to be a matrix full of definition variables.

Following code:

# definition variable
mxMatrix(
    type="Full",
    nrow=1,
    ncol=8,
    free=FALSE,
    labels=paste("data.age", c(7, 8, 1:6), sep=""),
    name="Age"
)

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 5 views
5 views
Problem: I had the problem when I tried to view a List generated trough a function that computes the intersect/difference of two sets of 20000 observations each. The function in question: jeepers.creepers<-function(dfx,dfy,by.x,by.y){ SetX<-dfx[[by.x]] SetY<- ... SetX and SetY 8584 -none- numeric Unique in SetX 15334 -none- numeric Unique in SetY 0 -none- numeric Does anyone knows whats happening?
asked Apr 26 anika11 32k points
0 votes
1 answer 8 views
8 views
Problem: I&rsquo;m new in data frame. I received this error message: Error in if (condition) { : missing value where TRUE/FALSE needed or Error in while (condition) { : missing value where TRUE/FALSE needed What does it mean, and how do I prevent it?
asked Mar 10 Sabbir Hossain 14.6k points
0 votes
1 answer 5 views
5 views
Problem: What caused the error"Error in if (empty(.data)) return(.data) : missing value where true/false needed " ?
asked Apr 26 salim1 60.6k points
1 vote
1 answer 301 views
301 views
Problem: I have some knowledge about R and Rstudio. Currently I am trying to install the package known as dplyr but it constantly shows me the below error: Error in install.packages : missing value where TRUE/FALSE needed. Please find below my console history for your ... very limited knowledge about R and Rstudio so I am unable to fix it. I am still facing the same error please guide me.
asked May 26, 2020 Martin K 6.6k points
0 votes
1 answer 6 views
6 views
Problem: I need to find the reason behind this problem,"R error missing value where true/false needed " .
asked Apr 26 salim1 60.6k points
0 votes
1 answer 8 views
8 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
asked Mar 30 tuhin1 48.9k points
0 votes
1 answer 3 views
3 views
Problem: When I encountered this problem, I attempted to find a solution on the internet but was unable to find any useful details. If you read the above query and understand what the solution is, please cooperate with me- Thanks.
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 9 views
9 views
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
asked Mar 30 tuhin1 48.9k points
1 vote
1 answer 41 views
41 views
Problem: Let me put it as sim as I can. I have an if statement in my code and it returns a value. Since IF is a boolean statement it should return value whether it&rsquo;s true or false. So, in my program when a method tests an argument and returns a true or ... as a parameter in a different method inside an IF statement. How should I do that? Any kind of help is appreciated by my side. Thanks.
asked Mar 17, 2020 Gavin 15.3k points
1 vote
1 answer 5 views
5 views
Problem: How to avoid eeror bars? Add error bars to barplot in r.
asked Mar 23 PkGuy 23.5k points