I have some data I need to do some computations/manipulation on:
data=[{"sex":"M","age":"0","pop":"310"},
{"sex":"M","age":"5","pop":"306"},
{"sex":"M","age":"10","pop":"313"},
{"sex":"M","age":"15","pop":"332"},
....
{"sex":"M","age":"100","pop":"4"},
{"sex":"W","age":"0","pop":"294"},
{"sex":"W","age":"5","pop":"291"},
{"sex":"W","age":"10","pop":"300"},
{"sex":"W","age":"15","pop":"318"},
....
{"sex":"W","age":"100","pop":"1"}
]
I extract the sub data for male (M) and for female (W) :
var male=data.filter(function(d){
if (data.sex=="M"){return d.pop;}
})
var female=data.filter(function(d){
if (data.sex=="F"){return d.pop;}
})
Now, I would like to compute the population (pop) for both sex i.e. create a new variable named "both" containing with respect of the variable "age" :
both=[{"sex":"MW","age":"0","pop":"604"},
{"sex":"MW","age":"5","pop":"597"},
{"sex":"MW","age":"10","pop":"613"},
{"sex":"MW","age":"15","pop":"650",
....
{"sex":"MW","age":"100","pop":"5"}
]
How do I do that?