View source: R/misc_functions.R
to_agegrp | R Documentation |
'to_agegrp' creates a new column
to_agegrp(
dtb,
grp_width = 5L,
max_age = 85L,
age_colname = "age",
agegrp_colname = "agegrp",
to_factor = TRUE,
min_age = NULL
)
dtb |
A data.table with a column named |
grp_width |
The group width for the age groups. |
max_age |
The max age for the closed age groups. For ages above the max age, an open age group will be created, named max_age+ (i.e. 85+). |
age_colname |
A string denoting the age column in |
agegrp_colname |
A string denoting the name of the column that will be created for age groups. |
to_factor |
A logical. If |
min_age |
The minimum age for the age group. If 'NULL' the minimum will be considered the that that is not more than the minimum age in the data that can be divided with grp_width |
a data.table, invisibly.
library(data.table)
library(CKutils)
to_agegrp(data.table(age = 0:99))[]
to_agegrp(data.table(age = 0:99), max_age = 80L)[]
to_agegrp(data.table(age = 0:99), grp_width = 10, max_age = 85)[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.