From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

agrep and fuzzy matching

agrep and fuzzy matching

- [Instructor] R provides a version of grep that allows for fuzzy matching. And let's take a look at how to use that. There's a function in R called Colors. And all it does is return a list of colors that are available to you as part of the R environment. I'm going to use it as an example. First of all, I'd like to find any colors that are blue. So I can use agrep, which is a fuzzy matching version of grep, and my pattern is blue. I'm going to search through colors. And again, Colors, the function, just returns a list of colors. So what I'll be doing is searching through the list of colors, and finding anything that has blue in it. Now what I get back is a collection of numbers. And what that is is an index into the list of colors provided by Colors. So if I type in colors, and hit return, what I can do is go up to the first value returned by agrep, which is two, and look at the second value of colors and you'll see that the second value is Alice blue. Likewise, if I look at the…

Contents