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.

strsplit() splits strings at matched characters

strsplit() splits strings at matched characters

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

strsplit() splits strings at matched characters

- [Instructor] Suppose you have a vector full of phone numbers or other items that need to be split at a certain delimiter. You can use strsplit to break vector parts apart based on the contents of a string. Let's take an example. Here I've created this vector, and I've combined bibbity.bibb and bobbity.bob and boo.boo. I'm going to run that, and you'll see I've created a vector with those three items in it. Now let's suppose that I want to break those words up into individual elements. I can use string split S-T-R-S-P-L-I-T, and then I put in a parentheses, and I'll call up the vector I want to split. In this case, vector, this vector. And I give it a character I want to split it on. Let's say I want to split on a B, and when I run that, you can see that I receive a list, and in each element of the list is an element of the vector, and each element of that vector has been split at the B's, so I have a new item in each…

Contents