title: extracting word from named vector in r through a variable
body: <p>I want to extract a specific word from a named vector having set of two words. </p>
  
  <pre><code>freq= c(23,34,45,21)
  names(freq) = c("good boy", "bad boy","good car","car good") 
  freq
  </code></pre>
  
  <p>I want all those words starting with good. The following works but i want to pass good in a variable t and then extract it by passing that variable but it's not working.
  How to tell r that t is a variable and not a character in itself  </p>
  
  <pre><code># it works  
  freq[grep("^good",names(freq))]   
  # passing in a variable
  t &lt;- "good"
  freq[grep("^t",names(freq))]  
  </code></pre>