Skip to content

Instantly share code, notes, and snippets.

@k-hench
Created August 9, 2021 10:27
Show Gist options
  • Save k-hench/a4deda1705b727e350cc8a15d8b3cafc to your computer and use it in GitHub Desktop.
Save k-hench/a4deda1705b727e350cc8a15d8b3cafc to your computer and use it in GitHub Desktop.
library(tidyverse)
library(lubridate)
library(fuzzyjoin)
test_a <- tibble(gr = letters[rep(1:3,each = 5)],
timestamp = runif(15,min = 0,max = 10^8) %>% as_datetime())
test_b <- tibble(year = rep(1970:1973, each = 2),
season = str_c(year,"_",rep(1:2, 4)),
season_start = str_c(year,rep(c("-01-01 00:00:00","-06-01 00:00:00"))) %>% as_datetime(),
season_end = str_c(year,rep(c("-05-31 23:59:59","-12-31 23:59:59"))) %>% as_datetime()) %>%
dplyr::select(-year)
test_a %>%
fuzzyjoin::fuzzy_join(test_b,
by = c(timestamp = "season_start", timestamp = "season_end"),
mode = "left",
match_fun = list(`>=`, `<=`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment