Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on your code, I would guess that this would work the full data set (depending on your system's memory): </p> <pre><code>chr1 &lt;- 33132539 window &lt;- 100 pos &lt;- cut(1:chr1, seq(0, chr1, window)) meanrho.chr1 &lt;- tapply(spe$rho, INDEX = pos, FUN = mean) </code></pre> <p>I think you want a factor that defines groups of intervals for every 100 within the first column (<code>rho</code>), and then you can use the standard apply family of functions to get means within groups. </p> <p>Here is the data you posted in reproducible form. </p> <pre><code>spe &lt;- structure(list(pos = c(5380L, 5390L, 5393L, 5404L, 5428L, 5437L, 5440L, 5443L, 5459L, 5463L, 5480L, 5521L, 5538L, 5584L, 5673L, 5720L, 5841L, 5880L, 5913L, 5958L), rho = c(30.07383, 30.87, 0.07383, 6, 30.07383, 1, 9, 30.07383, 6, 30.07383, 7, 30.07383, 0, 20, 30.07383, 30.07383, 3, 30.07383, 4, 30.07383)), .Names = c("pos", "rho"), row.names = c(NA, -20L), class = "data.frame") </code></pre> <p>Define the intervals with <code>cut</code>, we just want every 100th value (but you might want the details tweaked as per your code for your real data set). </p> <pre><code>pos.index &lt;- cut(spe$pos, seq(0, max(spe$pos), by = 100)) </code></pre> <p>Now pass the desired function (<code>mean</code>) over each group. </p> <pre><code>tapply(spe$rho, INDEX = pos.index, FUN = mean) </code></pre> <p>(Lots of NAs since we didn't start at 0, then)</p> <pre><code>(5.2e+03,5.3e+03] (5.3e+03,5.4e+03] (5.4e+03,5.5e+03] (5.5e+03,5.6e+03] (5.6e+03,5.7e+03] (5.7e+03,5.8e+03] (5.8e+03,5.9e+03] 20.33922 14.90269 16.69128 30.07383 30.07383 16.53692 </code></pre> <p>(Add other arguments to FUN, such as na.rm as necessary, e.g:)</p> <pre><code>## tapply(spe$rho, INDEX = pos.index, FUN = mean, na.rm = TRUE) </code></pre> <p>See <code>?tapply</code> applying over groups in a vector (ragged array), and <code>?cut</code> for ways to generate grouping factors.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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