title: agrep: only return best match(es)
body: <p>I'm using the 'agrep' function in R, which returns a vector of matches.  I would like a function similar to agrep that only returns the best match, or best matches if there are ties.  Currently, I am doing this using the 'sdist()' function from the package 'cba' on each element of the resulting vector, but this seems very redundant.</p>
  
  <p>/edit: here is the function I'm currently using.  I'd like to speed it up, as it seems redundant to calculate distance twice.</p>
  
  <pre><code>library(cba)
  word &lt;- 'test'
  words &lt;- c('Teest','teeeest','New York City','yeast','text','Test')
  ClosestMatch &lt;- function(string,StringVector) {
    matches &lt;- agrep(string,StringVector,value=TRUE)
    distance &lt;- sdists(string,matches,method = "ow",weight = c(1, 0, 2))
    matches &lt;- data.frame(matches,as.numeric(distance))
    matches &lt;- subset(matches,distance==min(distance))
    as.character(matches$matches)
  }
  
  ClosestMatch(word,words)
  </code></pre>