Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upScale-down function #22
Comments
|
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). |
fine_separate()and vice-versa.