• Register
0 votes
299 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

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

1 vote
1 answer 104 views
104 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 Martin K 6.6k points
1 vote
1 answer 26 views
26 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’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 Gavin 15.3k points
1 vote
2 answers 1.2K views
1.2K views
Problem : Currently I am learning Javascript. I know the expression false && anything is short-circuit evaluated to false. According to this information I can certainly expect false && true || true must be evaluate to the false. But this is not the case. I saw ... me in finding correct solution of below question. “What is the value of the following expression? true || true && false”?
asked Apr 6 morrisBson 3.2k points
0 votes
2 answers 51 views
51 views
Problems: I am new to programming, I need help, can anyone help me? Declare a variable isACustomer suitable for representing a true or false value?
asked Feb 14 maddi86 5.4k points
1 vote
1 answer 13 views
13 views
Problem: I am new in python programming an I have been learning for this some days. As a newbee I am still learning and and I am cofused about some things. My question is “In an if/else statement, if the boolean expression is always false?”
asked Apr 3 LizzyM 6.1k points