Преобразование секунд с 1 января 1970 года в дату / время.
growthfun<-function (a) {
r <- c()
s <- c()
for (i in seq_along(a)) {
if (a[i] >= max(a[1:(i-1)])) {
r <- c(r, as.POSIXct(index(a[i])))
s <- c(s, a[i])
}
else {
next
}
}
data.frame(row.names=as.POSIXct(r, origin = "1970-01-01", tz = ""), s)
}
growthfun(ts_1)
s
2020-04-20 22:31:28 50.13211
2020-04-20 22:44:05 50.23050
2020-04-20 22:53:49 50.42096
Данные :
ts_1 <- structure(c(50.1321122972067, 50.0355467742705, 49.9122834457642,
49.9948860954217, 50.0397819115463, 50.2304961977954, 49.8852887132391,
50.420955209067, 50.3734680543285, 50.2443255196795), .Dim = c(10L,
1L), .Dimnames = list(NULL, NULL), index = structure(c(1587396688,
1587396699, 1587396846, 1587397205, 1587397420, 1587397445, 1587397972,
1587398029, 1587398179, 1587398337), tzone = "", tclass = c("POSIXct",
"POSIXt")), class = c("xts", "zoo"), .CLASS = "double")
[,1]
2020-04-20 22:31:28 50.13211
2020-04-20 22:31:39 50.03555
2020-04-20 22:34:06 49.91228
2020-04-20 22:40:05 49.99489
2020-04-20 22:43:40 50.03978
2020-04-20 22:44:05 50.23050
2020-04-20 22:52:52 49.88529
2020-04-20 22:53:49 50.42096
2020-04-20 22:56:19 50.37347
2020-04-20 22:58:57 50.24433