How do I use grep() to get NAs from a vector?
i.e: when I try grep(NA, c(1,NA))
I get [1] NA NA
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You want
is.na():If you want the
NA, tryIf you don’t, negate the output from
is.na():One reason your code doesn’t work is that you gave
NAas the pattern. To R this means that the pattern is not defined, so whether either of the elements of the vector match this pattern is also undefined – hence both areNAin the output.