How does agrep matching work?











up vote
4
down vote

favorite












The agrep function gives some puzzling results and I'd like to understand its behavior better. For example:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 1)


Returns:
[1] "abc" "abcde" "abcef"



But the distance between "abcd" and "abcef" is 2. So I'm not sure why the third match shows up.



levenshteinDist("abcd","abcef") # gives the answer of 2


Also, I assume that the function would return only exact matches if distance cap is set at 0:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 0)


However, I get [1] "abcde" as a match



It would be really helpful if someone could explain how the matching in agrep works.










share|improve this question


















  • 2




    I suspect that the rather testily written Note section in ?agrep might apply here. ;)
    – joran
    May 15 '15 at 16:21










  • @joran are you referring to this: "Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of x (just as grep does) and not whole elements. See also adist in package utils, which optionally returns the offsets of the matched substrings." I read it but I don't fully understand it..not familiar with how grep works either
    – xyy
    May 15 '15 at 16:25












  • Yes, "this matches substrings of each element of x (just as grep does) and not whole elements". So "abcd" needs only to be within 1 of a substring of the comparison strings. It is looking for matches within (that is the word used in the Description section).
    – joran
    May 15 '15 at 16:28










  • @joran hm interesting, thanks for the response! So to clarify, the reason that "abcd" is matched to "abcef" in the first example is that if "d" is deleted from "abcd", it would be a match to the substring "abc" in "abcef"? Does this also mean that the transformations are always performed on the pattern argument?
    – xyy
    May 15 '15 at 16:40










  • I believe so, yes. I would describe it as "can I transform pattern into a substring of an element of x?" If yes, it matches. The source for agrep is here which would be the definitive answer, provided you know C.
    – joran
    May 15 '15 at 16:44















up vote
4
down vote

favorite












The agrep function gives some puzzling results and I'd like to understand its behavior better. For example:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 1)


Returns:
[1] "abc" "abcde" "abcef"



But the distance between "abcd" and "abcef" is 2. So I'm not sure why the third match shows up.



levenshteinDist("abcd","abcef") # gives the answer of 2


Also, I assume that the function would return only exact matches if distance cap is set at 0:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 0)


However, I get [1] "abcde" as a match



It would be really helpful if someone could explain how the matching in agrep works.










share|improve this question


















  • 2




    I suspect that the rather testily written Note section in ?agrep might apply here. ;)
    – joran
    May 15 '15 at 16:21










  • @joran are you referring to this: "Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of x (just as grep does) and not whole elements. See also adist in package utils, which optionally returns the offsets of the matched substrings." I read it but I don't fully understand it..not familiar with how grep works either
    – xyy
    May 15 '15 at 16:25












  • Yes, "this matches substrings of each element of x (just as grep does) and not whole elements". So "abcd" needs only to be within 1 of a substring of the comparison strings. It is looking for matches within (that is the word used in the Description section).
    – joran
    May 15 '15 at 16:28










  • @joran hm interesting, thanks for the response! So to clarify, the reason that "abcd" is matched to "abcef" in the first example is that if "d" is deleted from "abcd", it would be a match to the substring "abc" in "abcef"? Does this also mean that the transformations are always performed on the pattern argument?
    – xyy
    May 15 '15 at 16:40










  • I believe so, yes. I would describe it as "can I transform pattern into a substring of an element of x?" If yes, it matches. The source for agrep is here which would be the definitive answer, provided you know C.
    – joran
    May 15 '15 at 16:44













up vote
4
down vote

favorite









up vote
4
down vote

favorite











The agrep function gives some puzzling results and I'd like to understand its behavior better. For example:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 1)


Returns:
[1] "abc" "abcde" "abcef"



But the distance between "abcd" and "abcef" is 2. So I'm not sure why the third match shows up.



levenshteinDist("abcd","abcef") # gives the answer of 2


Also, I assume that the function would return only exact matches if distance cap is set at 0:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 0)


However, I get [1] "abcde" as a match



It would be really helpful if someone could explain how the matching in agrep works.










share|improve this question













The agrep function gives some puzzling results and I'd like to understand its behavior better. For example:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 1)


Returns:
[1] "abc" "abcde" "abcef"



But the distance between "abcd" and "abcef" is 2. So I'm not sure why the third match shows up.



levenshteinDist("abcd","abcef") # gives the answer of 2


Also, I assume that the function would return only exact matches if distance cap is set at 0:



agrep("abcd",c("abc","abcde","abcef"),value=T,max.distance = 0)


However, I get [1] "abcde" as a match



It would be really helpful if someone could explain how the matching in agrep works.







r fuzzy-comparison agrep






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 15 '15 at 16:06









xyy

18229




18229








  • 2




    I suspect that the rather testily written Note section in ?agrep might apply here. ;)
    – joran
    May 15 '15 at 16:21










  • @joran are you referring to this: "Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of x (just as grep does) and not whole elements. See also adist in package utils, which optionally returns the offsets of the matched substrings." I read it but I don't fully understand it..not familiar with how grep works either
    – xyy
    May 15 '15 at 16:25












  • Yes, "this matches substrings of each element of x (just as grep does) and not whole elements". So "abcd" needs only to be within 1 of a substring of the comparison strings. It is looking for matches within (that is the word used in the Description section).
    – joran
    May 15 '15 at 16:28










  • @joran hm interesting, thanks for the response! So to clarify, the reason that "abcd" is matched to "abcef" in the first example is that if "d" is deleted from "abcd", it would be a match to the substring "abc" in "abcef"? Does this also mean that the transformations are always performed on the pattern argument?
    – xyy
    May 15 '15 at 16:40










  • I believe so, yes. I would describe it as "can I transform pattern into a substring of an element of x?" If yes, it matches. The source for agrep is here which would be the definitive answer, provided you know C.
    – joran
    May 15 '15 at 16:44














  • 2




    I suspect that the rather testily written Note section in ?agrep might apply here. ;)
    – joran
    May 15 '15 at 16:21










  • @joran are you referring to this: "Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of x (just as grep does) and not whole elements. See also adist in package utils, which optionally returns the offsets of the matched substrings." I read it but I don't fully understand it..not familiar with how grep works either
    – xyy
    May 15 '15 at 16:25












  • Yes, "this matches substrings of each element of x (just as grep does) and not whole elements". So "abcd" needs only to be within 1 of a substring of the comparison strings. It is looking for matches within (that is the word used in the Description section).
    – joran
    May 15 '15 at 16:28










  • @joran hm interesting, thanks for the response! So to clarify, the reason that "abcd" is matched to "abcef" in the first example is that if "d" is deleted from "abcd", it would be a match to the substring "abc" in "abcef"? Does this also mean that the transformations are always performed on the pattern argument?
    – xyy
    May 15 '15 at 16:40










  • I believe so, yes. I would describe it as "can I transform pattern into a substring of an element of x?" If yes, it matches. The source for agrep is here which would be the definitive answer, provided you know C.
    – joran
    May 15 '15 at 16:44








2




2




I suspect that the rather testily written Note section in ?agrep might apply here. ;)
– joran
May 15 '15 at 16:21




I suspect that the rather testily written Note section in ?agrep might apply here. ;)
– joran
May 15 '15 at 16:21












@joran are you referring to this: "Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of x (just as grep does) and not whole elements. See also adist in package utils, which optionally returns the offsets of the matched substrings." I read it but I don't fully understand it..not familiar with how grep works either
– xyy
May 15 '15 at 16:25






@joran are you referring to this: "Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of x (just as grep does) and not whole elements. See also adist in package utils, which optionally returns the offsets of the matched substrings." I read it but I don't fully understand it..not familiar with how grep works either
– xyy
May 15 '15 at 16:25














Yes, "this matches substrings of each element of x (just as grep does) and not whole elements". So "abcd" needs only to be within 1 of a substring of the comparison strings. It is looking for matches within (that is the word used in the Description section).
– joran
May 15 '15 at 16:28




Yes, "this matches substrings of each element of x (just as grep does) and not whole elements". So "abcd" needs only to be within 1 of a substring of the comparison strings. It is looking for matches within (that is the word used in the Description section).
– joran
May 15 '15 at 16:28












@joran hm interesting, thanks for the response! So to clarify, the reason that "abcd" is matched to "abcef" in the first example is that if "d" is deleted from "abcd", it would be a match to the substring "abc" in "abcef"? Does this also mean that the transformations are always performed on the pattern argument?
– xyy
May 15 '15 at 16:40




@joran hm interesting, thanks for the response! So to clarify, the reason that "abcd" is matched to "abcef" in the first example is that if "d" is deleted from "abcd", it would be a match to the substring "abc" in "abcef"? Does this also mean that the transformations are always performed on the pattern argument?
– xyy
May 15 '15 at 16:40












I believe so, yes. I would describe it as "can I transform pattern into a substring of an element of x?" If yes, it matches. The source for agrep is here which would be the definitive answer, provided you know C.
– joran
May 15 '15 at 16:44




I believe so, yes. I would describe it as "can I transform pattern into a substring of an element of x?" If yes, it matches. The source for agrep is here which would be the definitive answer, provided you know C.
– joran
May 15 '15 at 16:44

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30264025%2fhow-does-agrep-matching-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30264025%2fhow-does-agrep-matching-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly