Re: [R] Fast multiple match function

2015-04-17 Thread Keshav Dhandhania
Hi Jeff, Indeed the data.table package does provide a much cleaner way to achieve the same functionality, and a lot of other functionality as bonus. Thanks for letting me know about it. On Tue, 7 Apr 2015 at 15:41 Jeff Newmiller wrote: > You might find the data.table package helpful. It uses a

Re: [R] Fast multiple match function

2015-04-07 Thread Jeff Newmiller
You might find the data.table package helpful. It uses an index sorted with a radix sort and minimizes moving the data around in memory. --- Jeff NewmillerThe . . Go Live... DCN:

Re: [R] Fast multiple match function

2015-04-07 Thread Keshav Dhandhania
Hi all, Thanks for the responses. Herve's example is a good small size example of what I wanted. > y <- c(16, -3, -2, 15, 15, 0, 8, 15, -2) > someCoolFunc(-2, y) [1] 3 9 > someCoolFunc(15, y) [1] 4 5 8 The requirement is that I want someCoolFunc() to run in O(number of matches) time, instead of

Re: [R] Fast multiple match function

2015-04-07 Thread Hervé Pagès
Hi Keshav, findMatches() in the S4Vectors/IRanges packages (Bioconductor) I think does what you want: library(IRanges) y <- c(16L, -3L, -2L, 15L, 15L, 0L, 8L, 15L, -2L) x <- c(unique(y), 999L) hits <- findMatches(x, y) Then: > hits Hits object with 9 hits and 0 metadata columns:

Re: [R] Fast multiple match function

2015-04-07 Thread Enrico Schumann
On Mon, 06 Apr 2015, Keshav Dhandhania writes: > Hi, > > I know that one can find all occurrences of x in a vector v by doing >> which(x == v). > > However, if I need to do this again and again, where v is remaining the > same, then this is quite inefficient. In my particular case, I need to do >

Re: [R] Fast multiple match function

2015-04-06 Thread William Dunlap
split() might help, but you should give a more complete explanation of your problem. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Apr 6, 2015 at 1:56 PM, Keshav Dhandhania wrote: > Hi, > > I know that one can find all occurrences of x in a vector v by doing > > which(x == v). > > Howeve

Re: [R] Fast multiple match function

2015-04-06 Thread David Winsemius
On Apr 6, 2015, at 1:56 PM, Keshav Dhandhania wrote: > Hi, > > I know that one can find all occurrences of x in a vector v by doing >> which(x == v). > > However, if I need to do this again and again, where v is remaining the > same, then this is quite inefficient. In my particular case, I need

[R] Fast multiple match function

2015-04-06 Thread Keshav Dhandhania
Hi, I know that one can find all occurrences of x in a vector v by doing > which(x == v). However, if I need to do this again and again, where v is remaining the same, then this is quite inefficient. In my particular case, I need to do this millions of times, and length(v) = 100 million. Does an