[R] How to detect a sequence of NA values?

arun smartpink111 at yahoo.com
Wed Jan 8 04:36:39 CET 2014


Hi,
Try:
rl <- rle(is.na(a))
 max(rl$lengths[rl$values])
#[1] 3


A.K.


Hi, 

I'd like to detect whether a vector contains a sequence of NA values of a certain length. So, for example, if I have a vector a = 
c(1,NA,NA,4,NA,NA,NA,5); how can I find what the longest sequence of NAs is (in this case 3)? 

Note that this is different from simply summing the number of NA values in the vector (which would be 5 in this case)... 

Thanks for your help !



More information about the R-help mailing list