Skip to content
Prev 167563 / 398502 Next

Efficiency challenge: MANY subsets

Many thanks for this example, which doesn't entirely cover my case since I 
have as many "indexes" entries as "sequences" entries. It was very 
educational none the less and I used it to come up with something a bit 
faster than what I had before. The main trick I used though was naming all 
entries in "sequences" and "indexes" likes so 
  name(indexes) <- seq(length(indexes)
and then do a lapply on "names(indexes)", which allows me to access both 
lists easily. What I end up with is this:

fragments <- lapply(
    names(indexes),
    function(x){
      lapply(
        indexes[[x]],
        function(.range){
          .range <- seq.int(
            .range[1], .range[2]
          )
          unlist(lapply(sequences[x], '[', .range),use.names=FALSE)
        }
      )
    }
  )

Although this is still quite slow, it's much faster than what I had before. 
Any further comments are highly welcome. I can send the real "sequences" and 
"indexes" as exported R objects ...

Thanks, Joh
jim holtman wrote:

            
"N","H","K","L","L","L","I","N","N","N","N","L","T","E","V","H","T","Y","F",
c("M","G","L","W","I","S","F","G","T","P","P","S","Y","T","Y","L","L","I"
"N","H","K","L","L","L","I","N","N","N","N","L","T","E","V","H","T","Y","