Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for sharing Ken.</p> <p>You could use:</p> <pre><code>x &lt;- myDataFrame$MyVariableName; x[x &gt; 100 &amp; x &lt; 180] </code></pre> <p>Yours may require less typing but the code is less generalizable to others if you're sharing code. I have a few time saver functions like that myself but use them sparingly because they may be slowing down your code (extra steps) and requires you to also include that code for that function when ever you share the file with someone else.</p> <p><strong>Compare writing length. Almost the same length:</strong></p> <pre><code>ss(mtcars$hp, 100 &lt; . &amp; . &lt; 180) x &lt;- mtcars$hp; x[x &gt; 100 &amp; x &lt; 180] </code></pre> <p><strong>Compare time on 1000 replications.</strong></p> <pre><code>library(rbenchmark) benchmark( tyler = x[x &gt; 100 &amp; x &lt; 180], ken = ss(mtcars$hp, 100 &lt;. &amp; . &lt; 180), replications=1000) test replications elapsed relative user.self sys.self user.child sys.child 2 ken 1000 0.56 18.66667 0.36 0.03 NA NA 1 tyler 1000 0.03 1.00000 0.03 0.00 NA NA </code></pre> <p>So I guess it depends on if you need speed and/or sharability vs convenience. If it's just for you on a small data set I'd say it's valuable.</p> <p><strong>EDIT: NEW BENCHMARKING</strong></p> <pre><code>&gt; benchmark( + tyler = {x &lt;- mtcars$hp; x[x &gt; 100 &amp; x &lt; 180]}, + ken = ss(mtcars$hp, 100 &lt;. &amp; . &lt; 180), + ken2 = ss2(mtcars$hp, 100 &lt;. &amp; . &lt; 180), + joran = with(mtcars,hp[hp&gt;100 &amp; hp&lt; 180 ]), + replications=10000) test replications elapsed relative user.self sys.self user.child sys.child 4 joran 10000 0.83 2.677419 0.69 0.00 NA NA 2 ken 10000 3.79 12.225806 3.45 0.02 NA NA 3 ken2 10000 0.67 2.161290 0.35 0.00 NA NA 1 tyler 10000 0.31 1.000000 0.20 0.00 NA NA </code></pre>
    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.
 

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