Note that there are some explanatory texts on larger screens.

plurals
  1. POconditional filtering / subseting data in linear distance data in r
    primarykey
    data
    text
    <p>Here is my small example: ........... </p> <pre><code>Mark &lt;- paste ("SN", 1:400, sep = "") highway &lt;- rep(1:4, each = 100) set.seed (1234) MAF &lt;- rnorm (400, 0.3, 0.1) PPC &lt;- abs (ceiling( rnorm (400, 5, 5))) set.seed (1234) Position &lt;- round(c(cumsum (rnorm (100, 5, 3)), cumsum (rnorm (100, 10, 3)), cumsum (rnorm (100, 8, 3)), cumsum (rnorm (100, 6, 3))), 1) mydf &lt;- data.frame (Mark, highway, Position, MAF, PPC) </code></pre> <p>I want to filter data which is less than 10 for PPC at the sametime greater than 0.3 for MAF. </p> <pre><code> # filter PPC &lt; 10 &amp; MAF &gt; 0.3 filtered &lt;- mydf[mydf$PPC &lt; 10 &amp; mydf$MAF &gt; 0.3,] </code></pre> <p>I have grouping variable - highway and each Mark has Position on the highway. For example highway 1 for first five marks:</p> <pre><code> 1.4 7.2 15.5 13.4 19.7 |-----|.......|.......|.....|.....| "SN1" "SN2" "SN3" "SN4" "SN5" </code></pre> <p>Now I want to pick any ~ 30 Marks such that they are well distributed in each highway based on the Position on each highway (consider different length of highway) and minimum distance between two picks is not less than 10. </p> <p>Edit: The idea (rough sketch) <img src="https://i.stack.imgur.com/Uk4Ss.jpg" alt="enter image description here"></p> <p>I could think a little bit on how to solve this question. Help appreciated. </p> <p><strong>Edits:</strong> Here something I could figure out: </p> <pre><code># The maximum (length) of each highway is: out &lt;- tapply(mydf$Position, mydf$highway, max) out 1 2 3 4 453.0 1012.4 846.4 597.6 min(out) [1] 453 #Total length of all highways totallength &lt;- sum(out) # Thus average distance at which mark need to be placed: totallength / 30 [1] 96.98 </code></pre> <p>For highway 1, the theoritical marks could be at: </p> <pre><code> 96.98, 96.98+ 96.98, 96.98+96.98+ 96.98, ........till it is less than maximum (length )for highway 1. </code></pre> <p>Thus theoritically we need to choose mark at every 96.98. But the marks placed in highway may not be foud at </p> <p><strong>note: the total outcome of selection of marks need not be exactly 30 (around 30)</strong> </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.
 

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