by” signals we are doing a per-group calculation, and the “
:=” signals to land the results in the original
data.table. This sort of window function is incredibly useful in computing things such as what fraction of a group’s mass is in each row.
It’s worth reading up on
data.table if you aren’t familiar with the great things it can do.