Reputation: 298
> x<-c(FALSE,FALSE)
> which(x)
integer(0)
> which(x)==0
logical(0)
> x<-c(FALSE,TRUE)
> which(x)
[1] 2
In my program,i don't know what x is,x is a logical vector,maybe contain TRUE,if it contain TRUE,print the order,if it don't contain TRUE at all,print 0.
Integer(0) is not the same as 0?what is the difference?what is the meaning of logical(0)?
which(x)
can not do,when no TRUE in x ,which(x)
can do,when there is TRUE in x.
how can i fulfil my target?
Upvotes: 0
Views: 68
Reputation: 206401
You can check if any value in the vector x is true with
any(x)
rather than which() so
if (any(x)) {
#print order
} else {
print(0)
}
Upvotes: 3