#' Declustering using a simple separation time
#' @param time numeric vector, e.g. julian days
#' @param x numeric vector of corresponding values
#' @param sep numeric separation time
#' @return index integer vector of peaks
#' @export
declusterSimpleSeparation <- function(time, x, sep) {
if (class(time)!="numeric") stop("time should be a numeric vector")
if (class(x)!="numeric") stop("x should be a numeric vector")
if (class(sep)!="numeric" | length(sep) != 1) stop("sep should be a numeric")
if (length(time) != length(x)) stop("time and x must have same length")
n <- length(x)
index <- integer(n)
j <- 1
i <- 1
while (i <= n) {
sepRange <- which(time %in% seq.int(time[i]-sep,time[i]+sep, by=1 ))
if (x[i] >= max(x[sepRange])) {
index[j] <- i
i <- max(sepRange) + 1
j <- j+1
} else {
i <- i+1
}
}
return(index[index!=0])
}
#' Decluster data
#' @param jdays integer vector of julian days
#' @param x numeric vector of corresponding values
#' @param sep numeric separation time
#' @export
declusterData <- function(jdays, x, sep) {
index <- declusterSimpleSeparation(jdays, x, sep)
x[-index] <- 0
return(x)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.