Skip to content
Prev 392091 / 398502 Next

Subsetting a vector using an index with all missing values

Hi all,

I stumbled on subsetting behavior that seems counterintuitive and
perhaps is a bug. Here's a simple example:
[1] NA NA NA NA NA NA NA NA NA NA

I would have expected 3 NAs (the length of the index), not 10 (all
values in x). Looked at the documentation for the subsetting operator
`[` but found nothing indicating that if the index contains all
missing data, the result is the entire vector.

I can work around the issue for a general 'index' using a somewhat
clunky but straightforward construct along the lines of
[1] NA NA NA

but I'm wondering if the behaviour above is intended.

Thanks,

Peter