Deloitte Interview Questions | What is the output for the below expression all(NA==NA)?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 3 )
Missing values (NA) and NaN values are regarded as non-comparable even to themselves,
so comparisons involving them will always result in NA.
NA
NA is identical to NA, but doesn’t equal it. If you run NA==NA, the response will be NA, because the equal operator doesn’t apply to NAs. From the identical documentation:
A call to identical is the way to test exact equality in if and while statements, as well as in logical expressions that use && or ||. In all these applications you need to be assured of getting a single logical value.
Users often use the comparison operators, such as == or !=, in these situations. It looks natural, but it is not what these operators are designed to do in R. They return an object like the arguments. If you expected x and y to be of length 1, but it happened that one of them was not, you will not get a single FALSE. Similarly, if one of the arguments is NA, the result is also NA. In either case, the expression if(x == y)…. won’t work as expected.