Reputation: 1188
After reading the comments section and then making the following changes, I am still getting a 'Success' instead of a 'Failure':
nrow(statedata)
[1] 100
num = -1
if(num != "best" & num != "worst" & num < 1 & num > nrow(statedata))
print("Failure!?")
else <br />
print("Success!")
[1] "Success!"
Upvotes: 1
Views: 4551
Reputation: 1188
Found the solution:
if(num != "best" & num != "worst" & (num < 1 | num > nrow(statedata)))
Thanks to all! Cheers.
Logical errors are so hard to find.
Upvotes: -1
Reputation: 563
Because of the condition:
if(num != "best" | num != "worst" | num < 1 | num > length(10))
You should use AND not OR in negation, else the other statement will always be true. I hope you got my point here.
Upvotes: 3