I'm trying to sum PONDERA when ESTADO==1 and then group by AGLOMERADO
new <- recorte %>% group_by(AGLOMERADO) %>%
summarise(TOTocupied=sum(recorte[recorte$ESTADO==1,"PONDERA"]))
The sum is working correctly, but I can't get the result to be grouped by AGLOMERADO, it gives me back the same result for each AGLOMERADO:
AGLOMERADO TOTocupied
1 100
2 100
3 100
What am I doing wrong?