This is related to the following: How to compute similarity in quanteda between documents for adjacent years only, within groups?
The two scripts below are the same e