Rainbow 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
16. The split() function
Summary

Instruction

The first step of the split-apply-combine pattern is to split the data into your desired groups. For example, when we analyzed the total number of pieces sold during the hours in which each administrator worked on Monday, we split our data frame into subgroups using administrator names.

If you don't want to use tapply(), you can split the data yourself using the split() function, which takes a vectorized object as input (like a vector or data frame) and splits it according to the column specified as the second argument. The result is a list were each member is actually one value from the column on which we're doing the splitting.

Here's an example. If we wanted to analyze how many bracelets we sold in a year, and we have sales statistics per month, then we'd begin by first splitting the data by the year column:

How spliting works

Exercise

Run the template and see the result.