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.

split

split

- [Instructor] There are times when you're going to want to split up a data frame by elements of that data frame, and that's what the split command is for. So let's take a look at that. First, we need some data, so let's grab the data ChickWeight, which is a data frame of chicken weight compared to food over time. So let's split that out by the chickens. So, we can call a variable called byChick and into that we're going to split, and this is the command we're talking about here. We're gonna split ChickWeight by ChickWeight and the chick variable. So when we do that, we hit return, and now we have a new variable called byChick. Let's take a look at that byChick. And this may be a little different than what you're expecting. Split produces lists, not data frames. And, under each list, what you've got is this is the chick number, and then you've got the weight time, the chick, and diet. So the first thing you need to know about split is just that it splits out into lists. Now, it's…

Contents