stats-na.contiguous: Find longest contiguous stretch of non-NAs or check for NAs

na.contiguousR Documentation

Find longest contiguous stretch of non-NAs or check for NAs

Description

Find the longest consecutive stretch of non-missing values in a "timeSeries" object. In the event of a tie, the first such stretch. Also, "timeSeries" method for is.na.

Usage

## S3 method for class 'timeSeries'
na.contiguous(object, ...)
## S4 method for signature 'timeSeries'
is.na(x)

Arguments

object, x

a "timeSeries" object.

...

further arguments passed to other methods.

Value

for the na.contiguous method, a "timeSeries" object without missing values,

for the is.na method, a "timeSeries" object whose data part is a logical matrix of the same dimension as in x indicating if the corresponding values are NA or not.

Examples

## Dummy 'timeSeries' containing NAs

data <- matrix(sample(c(1:20, rep(NA,4))), ncol = 2)
s <- timeSeries(data, timeCalendar(2023))
is.na(s)  
## Find the longest consecutive non-missing values
na.contiguous(s)

## tied longest stretches: 1:3, 6:9 and 10:12
x <- c(1:3, NA, NA, 6:8, NA, 10:12)
## should return the 1st one
na.contiguous(x)             # correct for R > 4.3.0
na.contiguous(timeSeries(x)) # correct for timeSeries version > 4030.106 

timeSeries documentation built on Sept. 30, 2024, 9:15 a.m.