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

Scale-down function #22

Closed
uribo opened this issue May 29, 2018 · 1 comment
Closed

Scale-down function #22

uribo opened this issue May 29, 2018 · 1 comment
Labels

Comments

@uribo
Copy link
Owner

uribo commented May 29, 2018

fine_separate() and vice-versa.

@uribo uribo added the feature label May 29, 2018
@uribo
Copy link
Owner Author

uribo commented May 29, 2018

idea

library(magrittr)

m <- c("493214294", "493214392", "493215203", "493215301")

coarse_gather <- function(meshcodes, distinct = FALSE) {
  
  res <- 
    meshcodes %>% 
    purrr::map_chr(
      function(x) {
        dplyr::case_when(
          jpmesh:::mesh_size(x) == units::set_units(0.5, "km") ~ substr(x, 1, 8),
          jpmesh:::mesh_size(x) == units::set_units(1, "km") ~ substr(x, 1, 6),
          jpmesh:::mesh_size(x) == units::set_units(10, "km") ~ substr(x, 1, 4)
        )
      }
    )
  
  if (rlang::is_true(distinct)) {
    res <- unique(res)
  }
  
  return(res)
  
}

coarse_gather(m)
#> [1] "49321429" "49321439" "49321520" "49321530"

coarse_gather(m) %>% 
  coarse_gather()
#> [1] "493214" "493214" "493215" "493215"

coarse_gather(m) %>%  
  coarse_gather(distinct = TRUE)
#> [1] "493214" "493215"

Created on 2018-05-29 by the reprex package (v0.2.0).

@uribo uribo closed this as completed in 566a89f May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant