title: Finding the Column Index for a Specific Value
body: <p>I am having a brain cramp.  Below is a toy dataset:</p>
  
  <pre><code>df &lt;- data.frame(
          id = 1:6, 
          v1 = c("a", "a", "c", NA, "g", "h"),
          v2 = c("z", "y", "a", NA, "a", "g"),
          stringsAsFactors=F)
  </code></pre>
  
  <p>I have a specific value that I want to find across a set of defined columns and I want to identify the position it is located in.  The fields I am searching are characters and the trick is that the value I am looking for might not exist.  In addition, null strings are also present in the dataset.</p>
  
  <p>Assuming I knew how to do this, the variable <em>position</em> indicates the values I would like returned.   </p>
  
  <pre><code>&gt; df
    id   v1   v2 position
  1  1    a    z        1
  2  2    a    y        1
  3  3    c    a        2
  4  4 &lt;NA&gt; &lt;NA&gt;       99
  5  5    g    a        2
  6  6    h    g       99
  </code></pre>
  
  <p>The general rule is that I want to find the position of value "a", and if it is not located or if v1 is missing, then I want 99 returned.</p>
  
  <p>In this instance, I am searching across v1 and v2, but in reality, I have 10 different variables. It is also worth noting that the value I am searching for can only exist once across the 10 variables.</p>
  
  <p>What is the best way to generate this recode? </p>
  
  <p>Many thanks in advance. </p>