2
I made a distribution by quantis of the Hdis of all municipalities in Brazil. The distribution was as follows:
0% 25% 50% 75% 100%
0.418 0.599 0.665 0.718 0.862
In my dataframe, there is a column with the percentage of votes each municipality gave to a particular candidate in the last presidential election. I’m trying to average this percentage by considering some HDI ranges, for example, between 0.418 and 0.599. I tried to do it this way:
mean(votos_idhm$PERC[votos_idhm$IDHM.2010 >= 0.418 & < 0.599], na.rm=TRUE)
However, the following error message appears:
Error: unexpected '<' in "mean(votos_idhm$PERC[votos_idhm$IDHM.2010 >= 0.418 & <"
Does anyone have any idea how to operationalize this? Thanks in advance!
The exact way you put it, it wasn’t. But I made some changes and it worked well: Mean(votos_idhm$PERC[which(votos_idhm$IDHM.2010 >=0.418 & votos_idhm$IDHM.2010 < 0.599)], na.rm=TRUE) Thank you very much!
– Guilherme Marques
OK. I will edit my answer so that there is no confusion between future users who might have the same question.
– Lucas
So. don’t need the which, just:
mean(votos_idhm[votos_idhm[["IDHM.2010"]] >= .418 & votos_idhm[["IDHM.2010"]] < .599, "PERC"], na.rm=TRUE)
– JdeMello