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.

duplicated and unique

duplicated and unique

- [Instructor] At some point you'll have a vector with a lot of elements, and some of them are duplicated, and you'll need to remove those duplications. R provides two functions, duplicated and unique, to accomplish that, so let's take a look at those. I've created a vector called bunchOLetters, which includes all the letters of the alphabet plus another instance of a, d, and m. So, a, d, and m are duplicated in bunchOLetters. To find those duplicates I can use duplicated, and then I'll give it bunchOLetters, and what I'm going to get is a Boolean response, and what this is saying is the first element of bunchOLetters is not duplicated, it's false, and so on, and so on, until you get to the last three elements, which are a, d, and m, those are duplicated, those are true. And I can change the behavior of duplicated, I can put in incomparables, and I would like to incomparable a, for example. Now you'll notice that instead of the last three elements being true, true, true it's false…

Contents