Note that there are some explanatory texts on larger screens.

plurals
  1. POCumulative frequency by factor
    primarykey
    data
    text
    <p>I have to find out the cumulative frequency, converted to percentage, of a continuous variable by factor. For example:</p> <pre><code>data &lt;- data.frame(n = sample(1:12), d = seq(10, 120, by = 10), Site = rep(c("FirstSite", "SecondSite"), 6), Plot = rep(c("Plot1", "Plot1", "Plot2", "Plot2"), 3) ) data &lt;- with(data, data[order(Site,Plot),]) data &lt;- transform(data, G = ((pi * (d/2)^2) * n) / 10000) data n d Site Plot G 1 7 10 FirstSite Plot1 0.05497787 5 9 50 FirstSite Plot1 1.76714587 9 12 90 FirstSite Plot1 7.63407015 3 10 30 FirstSite Plot2 0.70685835 7 5 70 FirstSite Plot2 1.92422550 11 1 110 FirstSite Plot2 0.95033178 2 3 20 SecondSite Plot1 0.09424778 6 8 60 SecondSite Plot1 2.26194671 10 6 100 SecondSite Plot1 4.71238898 4 4 40 SecondSite Plot2 0.50265482 8 2 80 SecondSite Plot2 1.00530965 12 11 120 SecondSite Plot2 12.44070691 </code></pre> <p>I need the cumulaive frequency of column <code>G</code> by factors <code>Plot~Site</code>in order to plot a geom_step ggplot of <code>G</code> against <code>d</code> for each plot and site.<br> I have achieved to compute cumulative sum of <code>G</code> by factor by:</p> <pre><code>data.ss &lt;- by(data[, "G"], data[,c("Plot", "Site")], function(x) cumsum(x)) # Gtot (data.ss.tot &lt;- sapply(ss, max)) [1] 9.456194 3.581416 7.068583 13.948671 </code></pre> <p>Now I need to express each <code>Plot</code> <code>G</code> in the range [0..1] where 1 is <code>G</code>tot for each <code>Plot</code>. I imagine I should divide <code>G</code> by its <code>Plot</code> <code>Gtot</code>, then apply a new <code>cumsum</code> to it. How to do it?<br> Please note that I have to plot this cumulative frequency against <code>d</code> not <code>G</code> itself, so it is not a proper ecdf.<br> Thank you.</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.
 

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