sort | R Documentation |
Sort a "timeSeries"
object with respect to its time stamps.
## S3 method for class 'timeSeries'
sort(x, decreasing = FALSE, ...)
## S4 method for signature 'timeSeries'
is.unsorted(x, na.rm = FALSE, strictly = FALSE)
x |
a |
decreasing |
a logical flag. Should we sort in increasing or decreasing order?
By default |
na.rm |
a logical value, should missing values be removed? |
strictly |
logical indicating if the check should be for strictly increasing values. |
... |
optional arguments passed to other methods. |
The method for sort
sorts x
either in increasing or
decreasing time stamp order.
The method for is.unsorted
returns TRUE
if the time
stamps of x
are not sorted in increasing order (including the
case when they are sorted in decreasing order) and FALSE
otherwise. is.unsorted
may also return NA
when there are
NA
s among the time stamps of x
.
All this is in line with the documented functionality of
base::is.unsorted
.
for sort
, a "timeSeries"
object,
for the is.unsorted
method, TRUE
, FALSE
, or
NA
, as described in section ‘Details’.
If is.unsorted
returns NA
when there are NA
s in
the data but not in the time stamps use library{timeSeries}
or
call the function as timeSeries::is.unsorted
. If you need more
details, read the rest of this note.
base::is.unsorted
'sees' the method for "timeSeries"
objects when package timeSeries is loaded (whether or not it is
attached). However, due to the way base::is.unsorted
is
implemented, it may give wrong answers when there are NA
's
among the values of the time series. Developers of packages applying
is.unsorted
on timeSeries objects should import if from package
timeSeries.
The above feature is not a shortcoming of base::is.unsorted
but
a consequence of the fact that the timeSeries method is not consistent
with its semantics. For example, it works on the time stamps, while
is.na
works on the data values.
is.unsorted
for further details on the NA
case
## a monthly calendar series
x <- daily2monthly(LPP2005REC[, 1:2])[3:14, ]
## resample the series with respect to the time stamps,
resampled <- sample(x)
## the time stamps are unordered
resampled
is.unsorted(resampled) # TRUE (i.e., not sorted)
## Now sort the series in decreasing time order
backward_in_time <- sort(resampled, , decreasing = TRUE)
## time stamps ordered in decreasing order
## but is.unordered requires increasing order:
backward_in_time
is.unsorted(backward_in_time) # still TRUE
## Is the reverted series ordered?
forward_in_time <- rev(backward_in_time)
forward_in_time
is.unsorted(forward_in_time) # FALSE (i.e., sorted)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.