find end of monotonic part of vector

4 messages
Open this post in threaded view
|

find end of monotonic part of vector

 Hallo all I have such data > dput(kalo.v) structure(list(cas = structure(c(1595847000, 1595847060, 1595847120, 1595847180, 1595847240, 1595847300, 1595847360, 1595847420, 1595847480, 1595847540, 1595847600, 1595847660, 1595847720, 1595847780, 1595847840, 1595847900, 1595847960, 1595848020, 1595848080, 1595848140, 1595848200, 1595848260, 1595848320, 1595848380, 1595848440, 1595848500, 1595848560, 1595848620, 1595848680, 1595848740, 1595848800, 1595848860, 1595848920, 1595848980, 1595849040, 1595849100, 1595849160, 1595849220, 1595849280, 1595849340, 1595849400, 1595849460, 1595849520, 1595849580, 1595849640 ), class = c("POSIXct", "POSIXt"), tzone = "UTC"), vodiv = c(999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 991.6404419, 925.2166748, 864.3446045, 812.1702271, 758.9353027, 722.5073242, 684.5323486, 652.5300293, 82.18816376, 141.1757813, 402.7521667, 999.9000244, 959.1779175, 967.0949707, 517.1983643, 50, 50, 524.569458, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 977.0491943, 889.9714355, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244)), row.names = 71211:71255, class = "data.frame") and I would like to automatically find endpoint of gradually decreasing part (here point 20, vodiv = 652.****). Usually I use diff but this is just a chunk of bigger data and diff seems to be difficult to use. I appreciate any hint. Best regards. Petr ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: find end of monotonic part of vector

 Hello, Maybe I'm not understanding but looking at this graph i <- diff(kalo.v\$vodiv) > 0 plot(kalo.v) lines(kalo.v) points(kalo.v\$cas[i], kalo.v\$vodiv[i], pch = 16, col = "red") it seems you want the point before the first local minimum? min(which(i)) - 1L #[1] 20 Hope this helps, Rui Barradas Às 13:05 de 07/08/20, PIKAL Petr escreveu: > Hallo all > > I have such data >> dput(kalo.v) > structure(list(cas = structure(c(1595847000, 1595847060, 1595847120, > 1595847180, 1595847240, 1595847300, 1595847360, 1595847420, 1595847480, > 1595847540, 1595847600, 1595847660, 1595847720, 1595847780, 1595847840, > 1595847900, 1595847960, 1595848020, 1595848080, 1595848140, 1595848200, > 1595848260, 1595848320, 1595848380, 1595848440, 1595848500, 1595848560, > 1595848620, 1595848680, 1595848740, 1595848800, 1595848860, 1595848920, > 1595848980, 1595849040, 1595849100, 1595849160, 1595849220, 1595849280, > 1595849340, 1595849400, 1595849460, 1595849520, 1595849580, 1595849640 > ), class = c("POSIXct", "POSIXt"), tzone = "UTC"), vodiv = c(999.9000244, > 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, > 999.9000244, 999.9000244, 999.9000244, 999.9000244, 999.9000244, > 999.9000244, 991.6404419, 925.2166748, 864.3446045, 812.1702271, > 758.9353027, 722.5073242, 684.5323486, 652.5300293, 82.18816376, > 141.1757813, 402.7521667, 999.9000244, 959.1779175, 967.0949707, > 517.1983643, 50, 50, 524.569458, 999.9000244, 999.9000244, 999.9000244, > 999.9000244, 999.9000244, 999.9000244, 999.9000244, 977.0491943, > 889.9714355, 999.9000244, 999.9000244, 999.9000244, 999.9000244, > 999.9000244, 999.9000244)), row.names = 71211:71255, class = "data.frame") > > and I would like to automatically find endpoint of gradually decreasing part > (here point 20, vodiv = 652.****). > > Usually I use diff but this is just a chunk of bigger data and diff seems to > be difficult to use. I appreciate any hint. > > Best regards. > Petr > > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.