0

The problem is the following

There is avector

k<-sample(1:100000,1000)
sort(k)->k

Then there is a matrix with ranges like

l<-c(1,100)
l1<-c(250,1000)
l3<-c(30000,60000)
l4<-c(80000,90000)
rbind(l,l1)->l
rbind(l3,l4)->ll
rbind(l,ll)->ll
ll->l3

Now I do have to find those numbers which are in the ranges of the table (like 1-100, or 30000 to 60000). Currently I use

indx <- sapply(k, function(x) any(x >= l3[,1] & x <= l3[,2]))

that is slow for a table (l3) with over 60k lines - is there any quicker way maybe?

heinwe
  • 9
  • 1
  • 7
  • You can use `cut` to get the grouping and then find the values in that group. – akrun Jan 27 '16 at 05:36
  • so i changed the 30k to 60k - if that is eadier to follow - sorry I dont understand how cut could help here – heinwe Jan 27 '16 at 05:45
  • 2
    @heinwe Please don't repost. This is exactly the same question as [**your previous**](http://stackoverflow.com/questions/35012734/find-ranges-in-matrix), just with some new numbers. You should provide enough information in the (original) post so people trying to help you understands the size of your problem, not spending their time in vain. – Henrik Jan 27 '16 at 06:46
  • well th orignal question is different in scope - right? it is unfair to assume that it hast o be larg scale while this is not! – heinwe Jan 27 '16 at 07:11
  • Why your comment to @Pierre Lafortune then ("is there any chance for a speed up? My table is like 60k lines and it takes really long")? – Henrik Jan 27 '16 at 07:52

0 Answers0