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

FEATURE: Add n_age_groups, n_years options for prioritization #33

Open
chacalle opened this issue Mar 31, 2021 · 2 comments
Open

FEATURE: Add n_age_groups, n_years options for prioritization #33

chacalle opened this issue Mar 31, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@chacalle
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When prioritizing using different reports of the same underlying data we often want to prioritize sources that have more detailed age groups or longer time series.

The current prioritization function requires creating a variable before hand related to the number of age groups or years from a source.

Describe the solution you'd like
Create helper functions to calculate the number of age groups or number of years of data

Describe alternatives you've considered
Add options directly to prioritize_dt. Is this too specific? And is it better to keep prioritize_dt simple?

Additional context
https://github.com/ihmeuw-demographics/demUtils/pull/32/files#r603528420

@chacalle chacalle added the enhancement New feature or request label Mar 31, 2021
@krpaulson
Copy link
Contributor

Are you imagining something like this?

# create function
add_count_cols <- function(dt, count_cols, id_cols) {
  for (col in count_cols) {
    dt[, (paste0("n_", col)) := length(unique(get(col))), by = id_cols]
  }
  return(dt)
}

# run example
dt <- data.table(
  id = c(1, 1, 1, 2, 2, 2),
  age = c(1, 2, 3, 1, 2, 2),
  year = c(2000, 2001, 2001, 2003, 2003, 2003),
  val = c(1:6)
)
count_cols <- c("age", "year")
id_cols <- "id"
dt <- add_count_cols(dt, count_cols, id_cols)

@chacalle
Copy link
Contributor Author

Yup I think so

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

No branches or pull requests

2 participants