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

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Aggregate

Aggregate

- [Instructor] You will frequently need to report on grouped data. And that's what aggregate is for. So let's take a look at the R command aggregate. First thing we need to do is get some data. So let's pull in ChickWeight, and then let's set up an aggregate command to report on that data. So the command is A-G-G-R-E-G-A-T-E, there's aggregate. And I would like to aggregate the weights of the chickens. So I'm going to use ChickWeight, there's the dataframe, and I'm going to select the weight column. I want to group it by each chick, so I'm going to hit return just to clean things up. I'm going to type in by equals, and I need to create a list of what I'm going to group by. So we'll call this chkID, which is the chick ID. That can be anything. And then I select a column that I'm going to group by. In this case it'll be ChickWeight, and the column is chick. So I'm going to group by the chicks. And when I group that, I want to apply a function, and the function that I'm going to apply is…

Contents