0

I'm trying to add a new variable (Day) to my df to indicate the first day an event occurs. For each batch the day value should be repeated until a new batch is listed. I've added some dummy data below. How can I do this?

df <- tibble(Batch=c(rep(123,5), rep(345,5)), Month = rep(seq(5),2))
df_day <- tibble(Batch= c(123,345), Day= c(3,6))

1 Answers1

0

standard left_join should work

library(dplyr)
left_join(df,df_day, by = "Batch")
dy_by
  • 1,061
  • 1
  • 4
  • 13