hadley / r4ds

R for data science: a book
http://r4ds.hadley.nz
Other
4.51k stars 4.19k forks source link

19.5.3 Rolling joins - parties example #1610

Open brtkl opened 9 months ago

brtkl commented 9 months ago

"And for each employee we want to find the first party date that comes after (or on) their birthday. We can express that with a rolling join:"

employees |> 
  left_join(parties, join_by(closest(birthday >= party)))

The sentence should rather be: "And for each employee we want to find the last party date that comes before (or on) their birthday. We can express that with a rolling join:"

Alternatively, the code could be updated as follows

employees |> 
  left_join(parties, join_by(closest(birthday <= party)))

if we want parties after birthdays as mentioned in the original sentence

florisvdh commented 5 months ago

I prepared PR #1645 to fix this issue.

Alternatively, the code could be updated as follows

employees |> 
  left_join(parties, join_by(closest(birthday <= party)))

if we want parties after birthdays as mentioned in the original sentence

True, but I haven't followed that since it would render the narrative and examples that come next obsolete.