Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

age_categories lowest age label incorrectly formatted #38

Open
AmyMikhail opened this issue Jul 12, 2023 · 1 comment
Open

age_categories lowest age label incorrectly formatted #38

AmyMikhail opened this issue Jul 12, 2023 · 1 comment

Comments

@AmyMikhail
Copy link
Collaborator


Problem:

When specific breaks are defined for the age_categories() function, there is special formatting for the upper number, but the lower number is incorrectly formatted as a range with itself.

For example, if the lowest number is 0, the label for the first category will be 0-0.

Proposed solution:

I think it should be reformatted to be less than the second number in the list of breaks, i.e. if the breaks are 0, 1, 5, 10 the first label should be <1.

Reprex below:

# Load epikit:
library(epikit)

# Vector of ages in years:
age <- c(3, 1, 8, 1, 0.5, 6, 7, 2, 11, 15)

# Create age categories:
agegroups <- epikit::age_categories(x = age, breakers = c(0, 1, 5, 10))

# Combine into a data.frame and sort ascending by age:
df <- data.frame(age, agegroups) %>% arrange(age)

This gives the following results:

> df
    age agegroups
1   0.5       0-0
2   1.0       1-4
3   1.0       1-4
4   2.0       1-4
5   3.0       1-4
6   6.0       5-9
7   7.0       5-9
8   8.0       5-9
9  11.0       10+
10 15.0       10+
@AmyMikhail
Copy link
Collaborator Author

Or possibly the rule should be:

  • if the interval between the first and second number in breakers is less than 2, then present the first label as <y (where y is the second number).
  • alternatively give the option in the function to specify if the lowest age category should be a range or less than the second number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant