I am working with a dataset of exposure over time and I would like to get all peaks over 1. I am doing it with the function pracma::findpeaks(), but the output I get it's not what I really want and I don't find how to fix it.
Here is an example with the code I am using:
#### Exemple ####
## Create dataset
time_initial <- seq(from = as.POSIXct("08:19:00", "%H:%M:%S", tz="UTC"), to = as.POSIXct("08:19:19", "%H:%M:%S", tz="UTC"), by = "1 sec")
time_min <- format(as.POSIXct(time_initial), format = '%H:%M:%S')
exposure <- c(0,0,2,3,5,0,0,4,5,6,0.5,0.25,0,0,0,0,4,5,0,0)
data <- as.data.frame(cbind(time_min, exposure))
## call peaks
data$exposure <- as.numeric(data$exposure)
peak <- findpeaks(data$exposure, nups = 1, ndowns = 1, sortstr = FALSE, threshold = 1)
## return times and not positions
peak_info <- data.frame(
peak_number = 1:nrow(peak),
time_peak_max = data[peak[,2],"time_min"],
peak_heigth = data[peak[,2],"exposure"],
peak_start = data[peak[,3],"time_min"],
peak_end = data[peak[,4],"time_min"])
The ouput I get returns all the peak, from 0 to 0, but I would like to get it from the first exposure over 1 to the last exposure over 1. With my example, the ideal code would return me the same 3 peaks, but for the intervals (08:19:02 - 08:19:04) ; (08:19:07 - 08:19:09) ; (08:19:16 - 08:19:17).
Maybe I'm not doing it with the correct function, but it is my first time working with peaks and I thought this would work.
Many thanks,
Miquel