Consider the following:
seq(from=10,to=30)[c(4,8)]
[1] 13 17
seq(from=10,to=30)[c(NA,8)]
[1] NA 17
seq(from=10,to=30)[c(NA,NA)]
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
To me the result of the latter is inconsistent with how the other two examples are handled by R and has cost me quite unpleasant debugging pains.
Might this be considered a bug?
seq(10, 30)
isNA
.[
is an extraction function. TheNA
you are trying to extract are not present in the sequence. – Pesachseq(from=10,to=30)[c(TRUE, FALSE)]
and see what you get. – Pesach(10:30)[NA]
to see what you get.R
's rules about dealing withNA
are quite explicit and are in fact consistent. – Glib(10:30)[c(NA,8)]
might be paraphrased into: "Return the 'not applicable' and 8th element", so why is "return the 'not applicable' element twice" not returningc(NA,NA)
? – Claudication