Why is c (1:10) [NA] the same as rep (10, NA)?

There are many ways to index things in R. Most of them make sense in context.

However, I cannot figure out what explains

> c(1:10)[NA]
 [1] NA NA NA NA NA NA NA NA NA NA

      

What's going on here?

+3


source to share


1 answer


This form of indexing is specifically mentioned in the documents (see ?"["

):




NAs when indexing

When retrieving a numeric, boolean, or character index, NA selects an unknown element and therefore returns NA to the corresponding Boolean, integer, numeric, complex, or character result, and NULL for a list. (It returns 00 for the original result.)

+4


source







All Articles