The difference between “letters[c(1,NA)]” and “letters[c(NA,NA)]“
Posted in R, statistics on April 22nd, 2010 by Tal Galili – 1 CommentIn David Smith’s latest blog post (which, in a sense, is a continued response to the latest public attack on R), there was a comment by Barry that caught my eye. Barry wrote:
Even I get caught out on R quirks after 20 years of using it. Compare letters[c(12,NA)] and letters[c(NA,NA)] for the most recent thing that made me bang my head against the wall.
So I did, and here’s the output:
1 2 3 4 5 | > letters[c(12,NA)] [1] "l" NA > letters[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 NA NA NA NA NA > |
Interesting isn’t it?
I had no clue why this had happened but luckily for us, Barry gave a follow-up reply with an explanation. And here is what he wrote:
read more »