title: R - compare multiple columns and create new columns indicating matches
body: <p>I'd like to know how I can compare multiple columns to the values in a single column, then use those matches to create a table of differences. I have a political dataset of policy outcomes, and whether certain organizations supported or opposed those outcomes, by year. Here's some mock data:</p>
  
  <p>Outcome 0 means the law never happened, outcome 1 means it happened.
  For organizations, a negative number means they opposed the law and positive means they supported it:</p>
  
  <pre><code>set.seed(123)
  Data &lt;- data.frame(
    year = sample(1998:2004, 200, replace = TRUE),
    outcome = sample(0:1, 200, replace = TRUE),
    union = sample(-1:1, 200, replace = TRUE),
    chamber = sample(-1:1, 200, replace = TRUE),
    pharma = sample(-1:1, 200, replace = TRUE),
    gun = sample(-1:1, 200, replace = TRUE),
    dem = sample(-1:1, 200, replace = TRUE),
    repub = sample(-1:1, 200, replace = TRUE)
  )
  </code></pre>
  
  <p>I would like to know how many times an organization matched the support or opposition of the union, per year. </p>
  
  <p>I imagine its going to be some table like this, where a match equals 1 and otherwise -1 (there are also many NAs in the data were organizations take no position):</p>
  
  <pre><code>DATA$contra &lt;- ifelse(DATA$union == page.bin$chamber, 1, -1)
  </code></pre>
  
  <p>In the dataset, there's about 50 organizations in consecutive columns. It seems unwieldy to create 50 new columns, one for each match. Even if that is the best way to do it, I don't know how to apply the function to create 50 new columns.</p>
  
  <p>Eventually, I'd like to create a heatmap or a way to visualize which organizations match the union column. But, first, I think, I need some kind of table of data.</p>
  
  <p>Thanks for your help!</p>