-4
I have a database union where the following operation needs to be performed with the VA column, broken down by state (UF):
Divide the sum of all observations below the median by the median multiplied by the number of observations below the median.
I was only able to calculate the state-disaggregated median using the following code::
median <- aggregate(x=uniao$VAA, by=list (uniao$UF.x), FUN=median)
Then, I could not proceed. Follow a sample of the base. Thanks.
~Cod.IBGE, ~UF.x, ~GastoMunEduc2017, ~Municipio, ~VAA,
2926657L, "BA", 293, "RIBEIRAO DO LARGO", "0,112045889",
2708501L, "AL", 5262048, "SAO LUIS DO QUITUNDE", "71,44668024",
3141108L, "MG", 118502319, "MATOZINHOS", "351,9522394",
1503309L, "PA", 1265213922, "IGARAPE-MIRI", "739,8046556",
2103802L, "MA", 425038332, "DOM PEDRO", "899,7424471",
2708105L, "AL", 524661607, "SANTANA DO MUNDAU", "2000,234872",
2807303L, "SE", 117161813, "TELHA", "2099,674068",
2407500L, "RN", 598046562, "MAXARANGUAPE", "2202,749768",
4303301L, "RS", 82870338, "CAIBATE", "2233,701833",
2108603L, "MA", 4369992772, "PINHEIRO", "2386,670001",
1304104L, "AM", 960827383, "TAPAUA", "2420,220108",