See how to use data.table’s special .SD symbol to perform calculations and other tasks by group
For some data.table users, “dot-SD” is a bit of a mystery. But data.table creator Matt Dowle told me that it’s actually quite simple: Just think of it as a symbol representing “each group.” Let’s go through a couple of examples.
I have a data set of daily cycling trips from the Boston area’s bicycle-share system. If you’d like to follow along, you can download the CSV file from the link at the bottom of this article.
I’ll load data.table and import my CSV file using data.table’s
fread()function. In the code below, I’m saving the data into a data table called mydt.