title: Selecting the option chosen in a discrete-choice experiment in R
body: <p>I have the following dataset, from a choice experiment:</p>
  <pre><code>   ID task opt q1 q2 q3 q4 q5 q6 q7 q8
  1   1    1   1  2  3  1  2  2  1  2  1
  2   1    1   2  2  3  1  2  2  1  2  1
  3   1    1   3  2  3  1  2  2  1  2  1
  4   1    2   1  2  3  1  2  2  1  2  1
  5   1    2   2  2  3  1  2  2  1  2  1
  6   1    2   3  2  3  1  2  2  1  2  1
  7   1    3   1  2  3  1  2  2  1  2  1
  8   1    3   2  2  3  1  2  2  1  2  1
  9   1    3   3  2  3  1  2  2  1  2  1
  10  1    4   1  2  3  1  2  2  1  2  1
  11  1    4   2  2  3  1  2  2  1  2  1
  12  1    4   3  2  3  1  2  2  1  2  1
  13  1    5   1  2  3  1  2  2  1  2  1
  14  1    5   2  2  3  1  2  2  1  2  1
  15  1    5   3  2  3  1  2  2  1  2  1
  16  1    6   1  2  3  1  2  2  1  2  1
  17  1    6   2  2  3  1  2  2  1  2  1
  18  1    6   3  2  3  1  2  2  1  2  1
  19  1    7   1  2  3  1  2  2  1  2  1
  20  1    7   2  2  3  1  2  2  1  2  1
  21  1    7   3  2  3  1  2  2  1  2  1
  22  1    8   1  2  3  1  2  2  1  2  1
  23  1    8   2  2  3  1  2  2  1  2  1
  24  1    8   3  2  3  1  2  2  1  2  1
  </code></pre>
  <p>Meaning individual 1 (<code>ID</code>) was asked 8 questions (<code>task</code>), each of which had 3 options (<code>opt</code>) she could choose from. The remaining columns (<code>q1...q8</code>) reflect the option she chose in each of the choice tasks. So, she chose option 2 on question 1 and, again, option 2 on question 7.</p>
  <p>I'm looking to turn it into a dataset that looks like this instead:</p>
  <pre><code>   ID task opt chosen
  1   1    1   1  FALSE
  2   1    1   2  TRUE 
  3   1    1   3  FALSE
  4   1    2   1  FALSE
  5   1    2   2  FALSE
  6   1    2   3  TRUE 
  7   1    3   1  TRUE 
  8   1    3   2  FALSE
  9   1    3   3  FALSE
  ...
  22  1    8   1  TRUE
  23  1    8   2  FALSE
  24  1    8   3  FALSE
  </code></pre>
  <p>In other words, a new column (<code>chosen</code>) reflects <code>TRUE</code> if that particular option was chosen in that particular question, and <code>FALSE</code> otherwise.</p>
  <p>I've tried all forms of <code>melt</code> and <code>reshape</code> and <code>cast</code> but I've come up empty.</p>
  <p>Thank you!</p>