Thanks, sorry I am new so may not be putting in good words .... one question, this code is giving me output as [1] 0 0 1 0 2. How can I transpose it in column so that I can see results in two columns
Beverly 0
Gloucester 0
Manchester-by-the-Sea Manchester
Nahant 0
Salem Salem
survey <- c("Salem", "salem, ma","Manchester","Manchester-By-The-Sea")
master <- c("Beverly","Gloucester","Manchester-by-the-Sea","Nahant","Salem")
n.match <- function(pattern, x, ...) {
matches <- numeric(length(pattern))
for (i in 1:length(pattern)) {
idx <- agrep(pattern[i],x,ignore.case=TRUE, max.distance = 2)
matches[i] <- length(idx)
}
matches
}
n.match(master,survey)