Average monthly pretax salary in Madrid: 2 575.46 EUR (source in es_ES: https://www.abc.es/espana/madrid/evolucionado-salario-medio-...)
Also, a shared apartment costs as much as you say. Not a room (source: idealista.es).
Purchase prices are high, but I'm curious as to what you consider a bad neighborhood, given the overall safety statistics in Spain, and Madrid in particular.
Housing affordability is a real problem, but misrepresenting data is counterproductive, as it can be easily disproven.
No one lives in rooms. Everyone in Madrid lives in apartment.
The average salary refers to those who have a job. Most family units have some that don't.