title: Fuzzy string matching of a list of character vectors to a character vector
body: <p>I have a list of character vectors and a single character vector. I would like to perform a fuzzy matching in R between each element of the list (a character vector) to each element of a character vector (a character string) and return the maximum similarity score for each combination. Below is a toy example:</p>
  
  <pre><code>a &lt;- c("brown fox", "lazy dog", "white cat", "I don't know", "sunset", "never mind", "excuse me")
  b &lt;- c("very late", "do not cross", "sunrise", "long vacation")
  c &lt;- c("toy example", "green apple", "tall building", "good rating", "accommodating")
  mylist &lt;- list(a,b,c)
  
  charvec &lt;- c("brown dog", "lazy cat", "white dress", "I know that", "excuse me please", "tall person", "new building", "good example", "green with envy", "zebra crossing")
  </code></pre>
  
  <p>Now, I would like to fuzzy match each element in <code>mylist</code> with the first string in <code>charvec</code> and return the maximum similarity score out of the 7 scores. Likewise, I want to obtain the score for each combination of <code>mylist</code> and <code>charvec</code>.</p>
  
  <p>My attempt so far:</p>
  
  <p>Convert the strings in charvec to the column names of an empty data frame</p>
  
  <pre><code>df &lt;- setNames(data.frame(matrix(ncol = 10, nrow = 3)), c(charvec))
  </code></pre>
  
  <p>Calculate the maximum similarity score between each combination using jarowinkler distance from RecordLinkage package (or if there is a better distance measure for matching phrases!!)</p>
  
  <pre><code>for (j in seq_along(mylist)) {
    for (i in length(ncol(df))) {
      df[[i,j]] &lt;- max(jarowinkler(names(df)[i], mylist[[j]]))
    }
  }
  </code></pre>
  
  <p>But unfortunately, I get only 3 scores in the first row with the rest of the values as NA.</p>
  
  <p>Any help on this would be highly appreciated.</p>