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

19.5.3 Rolling joins #1704

Open
hanguojun007 opened this issue Feb 5, 2025 · 0 comments
Open

19.5.3 Rolling joins #1704

hanguojun007 opened this issue Feb 5, 2025 · 0 comments

Comments

@hanguojun007
Copy link

Hi , I think this picture is wrong.
https://r4ds.hadley.nz/joins#fig-join-closest
this is example code:

library(dplyr)

# 示例数据
df1 <- tibble(
  time1 = c(1, 2, 3),
  value1 = c("A", "B", "C")
)

df2 <- tibble(
  time2 = c(1, 2, 4),
  value2 = c("X", "Y", "Z")
)
df1 %>%
  left_join(df2, by = join_by(closest(time1 <= time2)))

result is

# A tibble: 3 × 4
  time1 value1 time2 value2
  <dbl> <chr>  <dbl> <chr> 
1     1 A          1 X
2     2 B          2 Y     
3     3 C          4 Z
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