Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>perhaps you need <code>ifelse</code>? </p> <pre><code>teams &lt;- c("Arizona", "Oregon", "Colorado") data$conf &lt;- ifelse(data$team %in% teams &amp; data$year == 2011, "Pac-12", "something else") </code></pre> <hr> <p><em>Edit</em></p> <p>You can change things by subsetting as @Simplefish has shown you if you don't want the <code>if</code>. Although your question does ask for <code>if</code>s. </p> <p>The other way is to do all the changes at once so you dont overcopy the answers. You could nest your <code>if</code>s like:</p> <pre><code>ifelse(data$team %in% teams &amp; data$year == 2011, "Pac-12", ifelse(data$team %in% "Oklahoma" &amp; data$year == 2008, "second answer", "third answer")) </code></pre> <p>But with lots of conditions this is cumbersome so maybe you want:</p> <pre><code>reference &lt;- matrix(c(rep("Pac-12",3),rep("third answer",4), "Second Answer",rep("fourth answer",8)), 4, 4, dimnames=list(c("Arizona","Oregon", "Colorado", "Oklahoma"), c("2011","2008","2006","2005") ) ) #&gt; reference # 2011 2008 2006 2005 #Arizona "Pac-12" "third answer" "fourth answer" "fourth answer" #Oregon "Pac-12" "third answer" "fourth answer" "fourth answer" #Colorado "Pac-12" "third answer" "fourth answer" "fourth answer" #Oklahoma "third answer" "Second Answer" "fourth answer" "fourth answer" data$conf &lt;- with( data, reference [ cbind(team,year) ] ) # &gt; data # team year conf #1 Arizona 2006 fourth answer #2 Arizona 2006 fourth answer #3 Arizona 2011 Pac-12 #4 Oregon 2011 Pac-12 #5 Oklahoma 2008 Second Answer #6 Colorado 2005 fourth answer #7 Colorado 2005 fourth answer #8 Colorado 2011 Pac-12 </code></pre> <p>A final way would be to <code>merge</code> things using a data.frame version of reference.....I'm sure someone else might demonstrate this.</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