na.contiguous | R Documentation |
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
.
## S3 method for class 'timeSeries'
na.contiguous(object, ...)
## S4 method for signature 'timeSeries'
is.na(x)
object , x |
a |
... |
further arguments passed to other methods. |
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.
## 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.