I am a fan of data.table, as of writing re-usable functions for all current and future needs.
data.table
Here\'s a challenge I run into while working on the answer
Try:
dt <- copy(.dt)
It should work well.