Back-To-School Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The lapply() function
Other apply() functions
The split-apply-combine pattern
17. Applying split() to a column
Summary

Instruction

As you saw in the last instruction, each result list's member is actually a data frame. Each of those data frames contains data for monthly sales grouped by year.

But what if you don't want the whole data frame? What if you would just like to split the sold_pieces column per year? Of course, you can do that. In that case, the first argument to split() is not going to be the whole data frame sales_per_month. Rather, it's going to be your specific column of interest. See an example:

pieces_sold_per_year <- split(sales_per_month$sold_pieces, sales_per_month$year)

Exercise

Let's go ahead and split sold_pieces by year. Use the sales_per_month data frame, along with the sold_pieces and year columns. Store this information in a variable named pieces_sold_per_year.