I have a dataframe which looks like this:

```
df <- data.frame (
  time = rep(c("2010", "2011", "2012", "2013", "2014"),4),
  age = rep(c("40-44", "45-49", "50-54", "55-59", "60-64"),4),
 weight = rep(c(0.38, 0.23, 0.19, 0.12, 0.08),4),
 ethnic = rep(c(rep("M",5),rep("NM",5)),2),
 gender = c(rep("M",10), rep("F",10)),
 pop = round((runif(10, min = 10000, max = 99999)), digits = 0),
 count = round((runif(10, min = 100, max = 999)), digits = 0)
)
df$rate = df$count / df$pop

```

I want to calculate the direct age standardised incidence rates, where incidence rate = count/pop), and confidence intervals for these; for each subgrouping. So I would have a standardised rate for each combination of time, gender, ethnicity, age. Is there a way to do this in R?

I have tried using the function `ageadjust.direct` from the R package {epitools}, as so:

```
age_adjust_test <- ageadjust.direct(count = df$count, pop = df$pop, 
                                rate = df$rate, stdpop = df$weight)

```

The output from this is an overall adjusted rate, confidence intervals, and crude rate. Is there a way to get this output by each sub-group?