I have a data.frame structured as follows:
location gender 15.19 20.30 31.40 41.64 65.
New York Female 2 41 13 19 1
New York Male 1 23 15 17 2
San Francisco Female 1 27 14 14 3
San Francisco Male 4 24 14 10 1
Mexico City Female 1 40 26 11 3
Mexico City Male 4 23 35 8 3
Paris Female 2 12 10 6 0
Paris Male 1 20 13 11 1
...and need to turn it into a proportion table with each cell representing its proportion of the two rows for its given city. This is one solution but is there an easier way to do it for multiple columns (and just transform them without making new columns?)
EDIT Correct output would give each cell as a proportion of ALL cells within that city, so that all cells that share the location 'New York' would add up to 1, as would all cells that share location 'San Francisco', etc. i.e. :
location gender 15.19 20.30 31.40 41.64 65.
New York Female .01 .31 .1 .14 .01
New York Male .01 .17 .11 .13 .02