Take the 2-minute tour ×

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.

share|improve this question

closed as too broad by Roland, David, Waynn Lue, CT Zhu, Divi Jun 21 at 3:23


It might help if you could show a small selection of your data to play with. –  Henry Jun 5 '12 at 8:14
Your question is not very clear. However, I suggest looking at the msProcess package. It provides lots of interesting functions. –  Roland Jun 5 '12 at 9:41
What about something like this? rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=simecol:peaks –  Roman Luštrik Jun 5 '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 6 '12 at 7:13
The example data is in the following link stackoverflow.com/questions/10908553/… some one answer this. –  sathya Jun 6 '12 at 7:33

1 Answer 1

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)))


x <- c(1,3,1,3,1)

peaks(x, 1)
share|improve this answer
