Compare each row within each group
<p>Following dataset is reproducible</p>

<pre><code>group &lt;- c(1,1,2,2,3,3)
parameter &lt;- c("A","B","A","B","A","B")
values &lt;- c(10,20,20,5,30,50)
df &lt;- data.frame(group,parameter,values)

group parameter values
    1         A     10
    1         B     20
    2         A     20
    2         B      5
    3         A     30
    3         B     50
</code></pre>

<p>I want to check within each group whether A > B (store this result in fourth column for entire group)</p>

<p>If yes -> TRUE, If no -> FALSE</p>

<p>New Df:</p>

<pre><code>group parameter values  status
    1         A     10      FALSE
    1         B     20      FALSE
    2         A     20      TRUE
    2         B      5      TRUE
    3         A     30      FALSE
    3         B     50      FALSE
</code></pre>

<p>Approach</p>

<p>with(df, ave(values,group, FUN = function(x)  ))</p>

<p>I am not able to think what will be the code inside the function. Can someone please help me</p>

<p>Updated: Status should be ranked as per the values column (highest to lowest) per group</p>

<pre><code>group parameter values  status
    1         A     10      2
    1         B     20      1
    2         A     20      1
    2         B      5      2
    3         A     30      2
    3         B     50      1
</code></pre>