I have a table with two variables.The data is from NMR.So when I plot I get a spectrum.I found the peaks in plot.But I need to know how to list the values of peak and store them into a variable.Anyone please help.
Asked
Active
Viewed 3,171 times
-6
-
It might help if you could show a small selection of your data to play with. – Henry Jun 05 '12 at 08:14
-
What about something like this? http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=simecol:peaks – Roman Luštrik Jun 05 '12 at 10:16
-
I used peak function to find the peaks in plot.Even then i cant find the peaks with higher frequency value.The peak function is predicting even very small peaks in the plot.The peak function i used is peaks<-function(series,span=3){ z <- embed(series, span) s <- span%/%2 v<- max.col(z) == 1 + s result <- c(rep(FALSE,s),v) result <- result[1:(length(result)-s)] result } plot(ppm,freq, type="l") p <- which(peaks(freq, span=3)) points(ppm[p], freq[p], col="red") – sathya Jun 06 '12 at 07:13
-
The example data is in the following link http://stackoverflow.com/questions/10908553/how-to-find-peaks-in-r-plots.Please some one answer this. – sathya Jun 06 '12 at 07:33
-
I can only reiterate that there are packages that provide (somewhat more sofisticated) functions for peak detection. A quick google search even found me a package for evaluation of NMR data: http://www.stat.purdue.edu/~ovitek/BQuant-Web/BQuant/BQuant_1.0_Manual.pdf – Roland Jun 06 '12 at 08:29
-
Thanks for your answer.But after installing BQuant package when i load the package it shows following error **Error: package ‘BQuant’ is not installed for 'arch=i386'** Can you please sort it out. – sathya Jun 06 '12 at 09:28
-
Your question is not very clear. However, I suggest looking at the msProcess package. It provides lots of interesting functions. – Roland Jun 05 '12 at 09:41
1 Answers
5
An easy implementation based on Brian Ripley's post at R-help:
peaks <- function(x, halfWindowSize) {
windowSize <- halfWindowSize * 2 + 1
windows <- embed(x, windowSize)
localMaxima <- max.col(windows, "first") == halfWindowSize + 1
return(c(rep(FALSE, halfWindowSize), localMaxima, rep(FALSE, halfWindowSize)))
}
Example:
x <- c(1,3,1,3,1)
peaks(x, 1)
## [1] FALSE TRUE FALSE TRUE FALSE

sgibb
- 25,396
- 3
- 68
- 74