课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

grep

grep

- [Instructor] When working with strings, you'll often need to find one string inside of another string, and for that, we have grep. So let's take a look at that. First, you can see that I've created a vector called haystack, and in haystack, I've added red, blue, green, blue, and green forest, and these are all strings. Let's say, for example, that I want to find the word green in haystack, and what I can do is type in grep, and then I'll type in the string I'm searching for, which in this case is green, and the vector that I'm going to search, which in this case is haystack, and when I hit return, I get back three and five, and that tells me that in haystack, at position three and position five, you'll find green. Now notice that in position five of haystack, green forest, it's not just green. It's green forest. So grep searches inside of strings. Now, there's a couple of nuances to grep that we should cover, and let me show you how those work. First of all, I'm going to type in…

内容