对 R 中的两个列表进行 Regmatches

Regmatches over two lists in R

我在 word.library 的帮助下用以下代码找出了 targetframe 中的近似 machtes 的位置:

tragetframe <- data.frame(words= c("Important Words",
                                   "I would also Importante worde of thes substring",
                                   "No mention of this crazy sayingsys"))

word.library <- data.frame(mainword = c("important word",
                                        "crazy sayings"),
                           keyID =c("2000", "3000"))

##find position
find <- function(word.library, tragetframe) {
  aregexec(word.library, tragetframe, max.distance = 0.1)
}

positions <- lapply(word.library[,1], find, tragetframe[,1])

之后我想提取匹配的子串,但它不起作用:

extract <- function(tragetframe, positions ) {
  regmatches(tragetframe, positions)
}
extracted_machtes <- lapply(tragetframe[,1], extract, positions)

希望有人能帮我找到解决办法。

mapply(regmatches, tragetframe, positions)
     words             <NA>           
[1,] "Important Word"  Character,0    
[2,] "Importante word" Character,0    
[3,] Character,0       "crazy sayings"

?mapply 运行用其他对象的第一个元素输入的函数,然后是每个对象的第二个,依此类推。