I have a plot made from data frame z <- data.frame(x = c(1: 12), y = c(3,5,4,1,3,6,7,9,3,5,1,2))
. I want to subset the rows in the data frame corresponding to the selected point (see the red circles in the image enclosed). Any of you know how to do that? Thank you.
Asked
Active
Viewed 124 times
0

Hoang Le
- 308
- 1
- 3
- 14
-
1check out `pracma::findpeaks`. – Andre Elrico Feb 22 '18 at 12:07
-
3Cludgy, but hey... `z[which(sign(diff(z$y))!=lag(sign(diff(z$y)))),]` – Dan Feb 22 '18 at 12:11
-
Hi Lyngbakr, the code you suggested worked before but when I tried it again, it show "[1] x y <0 rows> (or 0-length row.names) ". Do you know what happened? Thank you. – Hoang Le Feb 22 '18 at 20:31
-
@HoangLe Without a reproducible example, no, I don't know what your issue is. Run `z <- data.frame(x = c(1: 12), y = c(3,5,4,1,3,6,7,9,3,5,1,2))` and then `z[which(sign(diff(z$y))!=lag(sign(diff(z$y)))),]` and it works fine. – Dan Feb 23 '18 at 10:33
-
@ Lyngbakr Thanks for you reply. It worked fine for me once when I got your answer earlier but it stops working afterward. However, I figured out the way to do on my data. And nice that you was patient to my questions :) – Hoang Le Feb 23 '18 at 11:01