How to catch integer(0)?

Roman Luštrik picture Roman Luštrik · Jun 23, 2011 · Viewed 115.3k times · Source

Let's say we have a statement that produces integer(0), e.g.

 a <- which(1:3 == 5)

What is the safest way of catching this?

Answer

Gavin Simpson picture Gavin Simpson · Jun 23, 2011

That is R's way of printing a zero length vector (an integer one), so you could test for a being of length 0:

R> length(a)
[1] 0

It might be worth rethinking the strategy you are using to identify which elements you want, but without further specific details it is difficult to suggest an alternative strategy.