Skip to content
Prev 38685 / 63424 Next

Surprising behavior of letters[c(NA, NA)]

On 18/12/2010 9:12 AM, Radford Neal wrote:
I agree that the behaviour is not particularly obvious, but I'm not so 
sure it should produce an error.  We should get an error when the input 
is likely to be accidental or due to a misconception and the output 
could be accepted and lead to wrong results later.  I think using an NA 
in a logical index is probably due to a misconception (e.g. thinking it 
is an NA_integer_), but the results are so weird that they are unlikely 
to pass unnoticed.

And presumably whoever chose this behaviour back in the ancient past 
thought there was some use in including NA in a logical index, and 
someone out there in the real world has made use of it.

But I wouldn't object if R version 3 gave errors for logical index 
vectors that were the wrong length or that contained NAs.

Duncan Murdoch