[R] SLLOOOWWW function ...

Johannes Graumann johannes_graumann at web.de
Tue Jul 17 13:32:07 CEST 2007


Does anybody have any insight into how to make this faster?
I suspect, that the rounding going on may be an issue, as is the stepping
through data frame rows using integers ...

If you have the patience to teach a noob, he will highly appreciate it ;0)

Joh

digit <- 4
for (minute in seq(from=25,to=lrange[2])){
  # Extract all data associtaed with the current time (minute)
  frame <- subset(mylist,mylist[["Time"]] == minute)
  # Sort by Intensity
  frame <- frame[order(frame[["Intensity"]],decreasing = TRUE),]
  # Establish output frame using the most intense candidate
  newframe <- frame[1,]
  # Establish overlap-checking vector using the most intense candidate
  lowppm <- round(newframe[1,][["Mass"]]-newframe[1,
[["Mass"]]/1E6*ppmrange,digits=digit)
  highppm <- round(newframe[1,][["Mass"]]+newframe[1,
[["Mass"]]/1E6*ppmrange,digits=digit)
  presence <- seq(from=lowppm,to=highppm,by=10^(-digit))
  # Walk through the entire original frame and check whether peaks are
overlap-free ... do so until max of 2000 entries
  for (int in seq(from=2,to=nrow(frame))) {
    if(nrow(newframe) < 2000) {
      lowppm <- round(frame[int,][["Mass"]]-frame[int,
[["Mass"]]/1E6*ppmrange,digits=digit)
      highppm <- round(frame[int,][["Mass"]]+frame[int,
[["Mass"]]/1E6*ppmrange,digits=digit)
      windowrange <- seq(from=lowppm,to=highppm,by=10^(-digit))
      if (sum(round(windowrange,digits=digit) %in%
round(presence,digits=digit)) < 1) {
        newframe <- rbind(newframe,frame[int,])
        presence <- c(presence,windowrange)
      }
    } else {
      break()
    }
  }



More information about the R-help mailing list