title: How can I extract values from a data.frame based on a vector in R?
body: <p>suppose I have a numeric vector like:</p>
  
  <pre><code>x &lt;- c(1.0, 2.5, 3.0)
  </code></pre>
  
  <p>and data.frame:</p>
  
  <pre><code>df&lt;-data.frame(key=c(0.5,1.0,1.5,2.0,2.5,3.0),
         value=c(-1.187,0.095,-0.142,-0.818,-0.734,0.511))
  
  df
    key  value
  1 0.5 -1.187
  2 1.0  0.095
  3 1.5 -0.142
  4 2.0 -0.818
  5 2.5 -0.734
  6 3.0  0.511
  </code></pre>
  
  <p>I want to extract all the rows in df$key that have the same values equal to x, with result like:</p>
  
  <pre><code>df.x$value
  [1] 0.095 -0.734  0.511
  </code></pre>
  
  <p>Is there an efficient way to do this please? I've tried data.frame, hash package and data.table, all with no success. Thanks for help!</p>
  
  <hr>
  
  <p>Thanks guys. I actually tried similar thing but got df$key and x reversed. Is it possible to do this with the <a href="http://cran.r-project.org/web/packages/hash/" rel="nofollow">hash()</a> function (in the 'hash' package)? I see hash can do things like:</p>
  
  <pre><code>h &lt;- hash( keys=letters, values=1:26 )
  h$a # 1
  
  h$foo &lt;- "bar"
  h[ "foo" ]
  h[[ "foo" ]]
  
  z &lt;- letters[3:5]
  
  h[z]
  &lt;hash&gt; containing 3 key-value pair(s).
  c : 3
  d : 4
  e : 5
  </code></pre>
  
  <p>But seems like it doesn't take an array in its key chain, such as:</p>
  
  <pre><code>h[[z]]
  Error in h[[z]] : wrong arguments for subsetting an environment
  </code></pre>
  
  <p>but I need the values only as in a vector rather than a hash. Otherwise, it would be perfect so that we can get rid of data.frame by using some 'real' hash concept.</p>