Here is what I am trying to do: When the term I am analyzing is "apples", I would like to know how many transpositions are needed to "apples" so that it can be found in a string.
"buy apples now" => 0 transposition needed (apples is present).
"cheap aples online" => 1 transposition is needed (apples to aples).
"find your ap ple here" => 2 transpositions are needed (apples to ap ple).
"aple" => 2 transpositions are needed (apples to aple).
"bananas" => 5 transpositions are needed (apples to bananas).
the stringdist and the adist functions don't work because they tell me how many transpositions are needed to transform one string into the other. Anyway, here is what I wrote so far:
#build matrix
a <- c(rep("apples",5),rep("bananas",3))
b <- c("buy apples now","cheap aples online","find your ap ple here","aple","bananas","cherry and bananas","pumpkin","banana split")
d<- data.frame(a,b)
colnames(d)<-c("term","string")
#count transpositions needed
d$transpositions <- mapply(adist,d$term,d$string)
print(d)