[R] SLLOOOWWW function ...

Michael Dewey info at aghmed.fsnet.co.uk
Wed Jul 18 17:43:14 CEST 2007


At 12:32 17/07/2007, Johannes Graumann wrote:
>Does anybody have any insight into how to make this faster?

I am not an expert on R programming by any means but I notice you are 
growing your new data frame row by row. I believe it is normally 
recommended to allocate enough space to start with.

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

Michael Dewey
http://www.aghmed.fsnet.co.uk



More information about the R-help mailing list