Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't have a bright idea, but you can get rid of the inner loop, and speed up things a bit. Notice that if a window falls fully wihtin a mylist interval, then you just have to add 100 to the corresponding <code>windows</code> element. So only the <code>st</code>-th and <code>sp</code>-th windows need special handling.</p> <pre><code> windows &lt;- numeric(100) for(i in 1:length(mylist)){ win &lt;- mylist[[i]] # for cleaner code st &lt;- floor(win[1]/100)+1 sp &lt;- floor(win[2]/100)+1 # start and stop are within the same window if (sp == st){ windows[st] &lt;- windows[st] + (win[2]%%100) - (win[1]%%100) +1 } # start and stop are in separate windows - take care of edges if (sp &gt; st){ windows[st] &lt;- windows[st] + 100 - (win[1]%%100) + 1 windows[sp] &lt;- windows[sp] + (win[2]%%100) } # windows completely inside win if (sp &gt; st+1){ windows[(st+1):(sp-1)] &lt;- windows[(st+1):(sp-1)] + 100 } } </code></pre> <p>I generated a bigger list:</p> <pre><code> cuts &lt;- sort(sample(1:10000, 70)) # random interval endpoints mylist &lt;- split(cuts, gl(35,2)) </code></pre> <p>and got 1.08 sec for 1000 replicates of this version versus 1.72 sec for 1000 replicates for the original. With real data the speed-up will depend on whether the intervals in <code>mylist</code> tend to be much longer than 100 or not.</p> <p>By the way, one could rewrite the inside loop as a separate function, and then <code>lapply</code> it over <code>mylist</code>, but that does not make it work faster.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload