似乎已经存在很多"密度函数峰值"线程,但我没有看到具体解决这一点.如果我错过了,很抱歉复制.
My problem: Given a vector of 1000 values (sample attached), I would like to identify the peaks in the histogram or density function of the data. From the image of the sample data below , I can see peaks in the histogram at ~0, 6200, and 8400. But I need the obtain the exact values of these peaks, preferably in a simple procedure as I have several thousand of these vectors to process.

I originally started working with the histogram outputs themselves, but couldn't get any peak-finding command to work properly (like, not at all). I'm not even sure how it would get the peaks() command from the splus2R package to work on histogram object or on a density object. This would still be my preference, as I would like to identify the exact data value of the max frequency of each peak (as opposed to the density function value, which is slightly different), but I can't figure that one out either.
I would post the sample data themselves, but I can't see a way to do that on here (sorry if I'm just missing it).
如果你的y值是平滑的(就像在你的样本图中那样),这应该可以非常重复地找到峰值:
peakx <- x[which(diff(sign(diff(y)))==-2)]
Run Code Online (Sandbox Code Playgroud)