View source: R/aggregate_age_counts.R

aggregate_age_counts | R Documentation |

`aggregate_age_counts()`

provides aggregation of counts across ages (in
years). It is similar to a `cut()`

and `tapply()`

pattern but optimised for
speed over flexibility. It takes a specified set of breaks representing the
left hand limits of a closed open interval, i.e [x, y), and returns the
corresponding interval and upper bounds. The resulting intervals span from
the minimum break through to the maximum age. Missing values are grouped as
NA.

```
aggregate_age_counts(counts, ages = seq_along(counts) - 1L, breaks)
```

`counts` |
Vector of counts to be aggregated. |

`ages` |
Vector of age in years. Double values are coerced to integer prior to categorisation / aggregation. For No (non-missing) age can be less than the minimum break. |

`breaks` |
1 or more cut points in increasing (strictly) order. These correspond to the left hand side of the desired intervals (e.g. the closed side of [x, y). Double values are coerced to integer prior to categorisation. |

A data frame with 4 entries; `interval`

, `lower_bound`

, `upper_bound`

and an
associated `count`

.

```
# default ages generated if only counts provided (here ages will be 0:64)
aggregate_age_counts(counts = 1:65, breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L))
# NA ages are handled with their own grouping
ages <- 1:65
ages[1:44] <- NA
aggregate_age_counts(
counts = 1:65,
ages = ages,
breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L)
)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.