Skip to content

finding and describing missing data runs in a time series

3 messages · Durant, James T. (ATSDR/DTEM/PRMSB), michael.weylandt at gmail.com (R. Michael Weylandt, (Ted Harding)

Not at a computer to test this but perhaps

rle(is.na(x))

might help. 

Michael
On Feb 12, 2012, at 7:36 PM, "Durant, James T. (ATSDR/DTEM/PRMSB)" <hzd3 at cdc.gov> wrote:

            
#
On 13-Feb-2012 Durant, James T. (ATSDR/DTEM/PRMSB) wrote:
You might consider an approach based on

  rle(is.na(mydata$pm25))

See ?rle

Example:

  X <- c(1,2,3,NA,NA,NA,4,5,NA,6,7,8,NA,NA,NA,NA,NA)
  X
  # [1]  1  2  3 NA NA NA  4  5 NA  6  7  8 NA NA NA NA NA
  rle(is.na(X))
  # Run Length Encoding
  #   lengths: int [1:6] 3 3 2 1 3 5
  #   values : logi [1:6] FALSE TRUE FALSE TRUE FALSE TRUE

Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 13-Feb-2012  Time: 08:51:19
This message was sent by XFMail