Finally we get to the last third of the square bracket syntax structure, by. This controls which variable (or variables) to group on. Learning to use this argument will allow us to answer some more interesting questions about my listening habits.
Since each record in our data set is one track listened to, if we group by the artist, and get a count of the number of records in each group, we should get a count of songs listened to by artist. Can you guess how we might do this using data.table?
::author pauses and looks at the reader painfully long::
That’s right! We use the .N special variable while grouping on artist. Let’s do this and chain a call to order the N variable in descending order using order(-N) ...