The problem is difficult for me to solve.
I need to count the number of matching items of variable "val" for each combination of variable "key", t