patrickm663 / HMD.jl

Makes it easy to get data from Human Mortality Database (HMD) into Julia!
https://patrickm663.github.io/HMD.jl/dev/
MIT License
6 stars 0 forks source link

Feat: add `transform()` function to produce tables with age-wise rows and year-wise columns #6

Closed patrickm663 closed 7 months ago

patrickm663 commented 7 months ago

When dealing with mortality data, it is typical to 'square' it into an $n\times m$ matrix, where entries $m(x,t)$ correspond to the mortality rate for a life aged $x$ in cohort/year $t$.

A function like transform() & transform!() could take in mortality date and apply this transformation. Where there are multiple representations of the mortality data (e.g. males, females, total), a Dict could be returned with DataFrame objects as values, so t["Males"] returns a DataFrame of transformed Male rates. Similarly, a custom struct could work.

patrickm663 commented 7 months ago

This will basically be a wrapper for DataFrames.unstack(df, :Year, :Male) but to handle cases where e.g. :Male may be ambiguous and there may be arbitrary columns to handle.