To make my abstract question more tangible, I want to calculate stratum-specific incidence rates of a particular disease for each age stratum. But I want to be able to write flexible code that can adapt to a variety of user-specified levels of granularity in age categorization. For instance, I might be interested in calculating incidence among children <2 mos of age, 2-3 mos, 4-5 mos, 6-11 mos, 12-23 mos, and 24-59 mos (most granular treatment of age). But I also want to perform the same calculation for a coarser treatment of age (i.e., <12 mos of age, 12-23 mos, 24-59 mos). So I want to be able to change the cutpoints at will.
Example:
incidence <- (age group freq)/(census pop for age group) * 100000
I am thinking that I could set a control structure function (i.e., if age < 12 mo then agegroup=1, etc) as an object and reference that object in an *apply function (given that I'm wanting to calculate these values across a number of dataframes), but I'm wondering if there is a better way to solve this problem. Am happy if you reference me to papers or give a specific answer here. Thank you.