Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's walk through what you did here.</p> <pre><code>data=c(0.6666667, 0.8333, 0.6666667, 0.8333, 0.8333, 0.75, 0.9999, 0.7499667, 0.25, 0.6666667, 0.1667, 0.7499667, 0.5, 0.2500333, 0.3333667, 0.0834, 0.0001, 0.2500333, 0.8333, 0.9999, 0.9999, 0.2500333, 0.2500333, 0.3333667, 0.9166, 0.5, 0.2500333, 0.4166667, 0.0001, 0.1667333, 0.6666333, 0.0834, 0.1667, 0.6666333, 0.9166, 0.1667, 0.7499333, 0.9166, 0.9166, 0.9166, 0.7499667, 0.7499667, 0.4166667, 0.5, 0.2500333, 0.9166, 0.6666667, 0.1667333, 0.25, 0.0001, 0.3333667, 0.0001, 0.25, 0.0834, 0.9999, 0.0834, 0.1667, 0.5, 0.2500333, 0.3333667, 0.9166, 0.9166, 0.8333, 0.9166, 0.75, 0.0834, 0.4166667, 0.5, 0.0001, 0.9999, 0.8333, 0.6666667, 0.9166) data_med=median(data) ## 0.5 quant_data=data ## irrelevant quant_data[quant_data&gt;data_med]="High" </code></pre> <p>But by doing this <strong>you have converted quant_data to a character vector</strong>:</p> <pre><code>str(quant_data) ## chr [1:73] "High" "High" "High" "High" "High" "High" "High" ... </code></pre> <p>Now the comparison between a character value and the <code>data_med</code> value is almost meaningless, because <code>data_med</code> will get coerced to a character value too:</p> <pre><code>"High" &lt; "0.5" ## FALSE "1e-4" &lt; "0.5" ## FALSE -- this is your problem. quant_data[quant_data&lt;=data_med]="Low" </code></pre> <p>What you presumably <em>meant</em> to do (and a reason to assign <code>quant_data=data</code>) was:</p> <pre><code>quant_data[data&gt;data_med]="High" quant_data[data&lt;=data_med]="Low" table(quant_data) ## High Low ## 35 38 </code></pre> <p>As @Arun points out in comments above, <code>quant_data &lt;- ifelse(data&gt;data_med,"High","Low")</code> would work too. So would an appropriate use of <code>cut()</code>.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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