Time Series Subsetting by NA and length

This is awesomely simply and just what I needed! Thanks as well for taking the time to show how to make the example reproducible.

Edit: the output from this is a list with length and values. max(run) would return the same type of result as na.contiguous from what I can tell. i.e. the longest sequence of !NA results.

What I am looking for though is for the ALL the sequences with no NAs in them (so that I can compare between them) - probably as indices.

So far as I can tell, the way to do this is to return the indices of the list items from the rle() function that pass a logical test (length > x & value==TRUE). Then, sum the lengths of all the list entries that come before each of these indices to get the start index of the sequence in the original dataframe.

1 Like