I'm trying to calculate Shannon diversity index for trees in a urban context. I have the following attribute table which I got joining attributes by location between a vector points and a vector grid. The field "res" has the tree species from the point layer. The field "id_malla" has the grid identifier ("id malla" means grid ID in Spanish).
I got the field "act_tot_id" by counting total number of points in every grid cell with the expression:
count("res", "id_malla")
I got the field "act_div_id", which is the number of species by each cell code, by the field calculator with this expression:
count_distinct(“res”, “id_malla”)
The issue comes when I try to calculate the number of individuals within each species by cell code ("id_malla"). I've tried several times with many combinations but I can't get the result. Here are a few of the expressions I've tried:
count("res", "act_tot_id", "id_malla")
count("res", "id_malla", "act_div_id")
count("res", "res", "act_div_id")
None of these gives any proper result
Can someone help with this?