2015-08-26 59 views
0

我想通了近似machtes的位置在targetframeword.library的幫助下用下面的代碼:Regmatches在R中兩個列表

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) 

希望有人能幫我找到解決辦法。

回答

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

?mapply運行與其他對象的第一個元素,則每個的第二等輸入的功能。