Note that there are some explanatory texts on larger screens.

plurals
  1. POaggregating and ifelse functions in R
    text
    copied!<p>Attached is some R code:</p> <pre><code>temp_df &lt;- data.frame(c("A","A","A","G","G","Z","Z"), c("B","D","E","R","S","Y","U"), c(1.5,1.1,0.8,0.2,0.8,0.9,0.1), c(0.8,0.4,1.5,1.2,1.2,0.2,0.3), c(2.7,2.7,2.7,2.4,2.4,0.5,0.5), c("YES","NO","NO","NO","NO","YES","YES")) colnames(temp_df) &lt;- c("PERSON_1","PERSON_2","VALUE_1", "VALUE_2","TOTAL_2","DECISION_2") </code></pre> <p>What I am trying to do is create a new column called "NEW_DECISION_1" based on the following rules:</p> <p>For the people in column 1 ("PERSON_1"), if the value of the corresponding values in column 5 ("TOTAL_2") is greater than or equal to 2.0 and there is a least one "YES" in the corresponding values in column 6 ("DECISION_2"), then the value for the "NEW_DECISION_1" column will be "YES", and if these criteria are not satisfied, then they will get a "NO" value.</p> <p>So for the A person in column 1, since the values in column 5 is 2.7 and there is at least one "YES" in the corresponding values in column 6 then the value in the new column will be "YES".</p> <p>For the G person in column 1, since the values in column 5 is 2.4 but since there are no "YES" values in the corresponding values in column 6, the value in the new column will be "NO".</p> <p>For the Z person in column 1, since the values in column 5 is 1.0 and there is at least one "YES" in the corresponding values in column 6, the value in the new column will be "NO". So the new table will be:</p> <pre><code>temp_df$NEW_DECISION_1 &lt;- c("YES","YES","YES","NO","NO","NO","NO") temp_df </code></pre> <p>I am thinking of some sort of aggregation rule but I am not sure what function to use to search for "least one "YES"".</p> <p>If you need any more information or clarification, please let me know.</p>
 

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