Skip to contents

This function takes a dataset and adds a new column that contains age groups.

Usage

construct_weight_group(
  dataset,
  weight_col,
  group_size = 0.5,
  new_col = "birth2c"
)

Arguments

dataset

A data frame containing at least one column with age values.

weight_col

The name of the column containing age values.

group_size

An integer specifying the size of the age groups. Default is 5.

new_col

The name of the new column to store the age groups. Default is "fert_age_grp".

Value

A data frame with the new column added, containing age groups.

Examples

df <- data.frame(id = 1:10, weights = c(23, 45, 34, 56, 29, 12, 67, 44, 33, 55))
new_df <- construct_age_group(df, age_col = "weights", group_size = 0.25)
print(new_df)
#>    id weights fert_age_grp
#> 1   1      23     23-22.25
#> 2   2      45     45-44.25
#> 3   3      34     34-33.25
#> 4   4      56     56-55.25
#> 5   5      29     29-28.25
#> 6   6      12     12-11.25
#> 7   7      67     67-66.25
#> 8   8      44     44-43.25
#> 9   9      33     33-32.25
#> 10 10      55     55-54.25