Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

/peakfinder.r Secret

Created May 12, 2013 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e7fc25e6074efdf8b5f1 to your computer and use it in GitHub Desktop.
Save anonymous/e7fc25e6074efdf8b5f1 to your computer and use it in GitHub Desktop.
# found on http://stackoverflow.com/questions/13133297/calculating-peaks-in-histograms-or-density-functions
peakfinder <- function(d){
dh <- hist(d,plot=FALSE)
dens <- dh[["density"]]
nbins <- length(dens)
ss <- which(rank(dens) %in% seq(from=nbins-2,to=nbins))
dh[["mids"]][ss]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment