I would like to find the date of the minimum and maximum values in an R ts()
object. I tried the which.min
and which.max
functions but they only return the "row number." I would like to output the actual Date. Thank you.
data <- ts(round(rnorm(60), 2), frequency = 12, end = c(2016, 12))
data
which.min(data)
which.max(data)
My favourite tool for time series is xts
, and ts
objects translate cleanly:
library(xts)
x = as.xts(data)
Outputs:
> min(index(x))
[1] "Jan 2012"
> max(index(x))
[1] "Dec 2016"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With