Crossprod of two different matrices by a factor/group

Hi, can you provide a reproducible example of what your dataset looks like and what you're after?