Filter string with min distance in r I have the following sample data:

target &lt;- "Stackoverflow"
candidates &lt;- c("Stackflow", "Stackflow", "Stckoverfow")


I would like to filter the string from candidates that has the lowest (levensthein) distance to the target string.

I decided to use the pipe operator to improve readability. However, i find it suboptimal that adist doesnt return the strings that corresponds to the distances.

My attempts:

Version 1) 

library(magrittr)    
candidates  %&gt;%  
  adist(y = target) %&gt;% 
  which.min %&gt;% 
  `[`(x = candidates, i = .)


Version 2)

library(dplyr)
candidates %&gt;% 
  adist(y = target) %&gt;% 
  data.frame(dist = ., candidates = candidates) %&gt;% 
  filter(dist == min(dist)) %&gt;% select(candidates)


Goal:

I want to Improve readability. Memory usage or performance do not matter as data
is pretty small. Using additional packages, like dplyr, is also fine.

In version 1 i think 
     `[`(...) is bad to read.

Version 2 seems better to me. But it does not seem optimal to me, that i have to add the strings to the data.frame after having applied adist() to them: data.frame(dist = ., candidates = candidates).
What is wrong with simple code like?:

distances &lt;- adist(candidates, target)
candidates[distances == min(distances)]


This is shorter and, in my opinion, easier to read, as it do not require any knowledge of additional packages.

Also, you mentioned that your data is small and it looks like you are working with vectors, in that case I do not see a point to use data.frame, dplyr etc.