I have a data frame with weekly section data. Each section has data for 104 weeks and a total of 83 sections.
I have a second data frame with a start and end week for the section that I want to filter the main data frame.
In both tables, Week is a combination of Year and Week, for example. 201501 and always from 1 to 52 weeks.
So, in the example below, I want to filter section A by week 201401 to 201404, section B, by week 201551 to 201603.
I initially thought that I could add an additional column to the Weeks_Filter data frame, which is the serial number from the beginning and the end of the weeks for each section (duplicating each row for every week), then combine 2 tables and save all the data from the Weeks_Filter table (all.y = TRUE) because it worked on a small sample that I made, but I donโt know how to add consecutive weeks, as they can span different years.
Week <- c("201401","201402","201403","201404","201405", "201451", "201552", "201601", "201602", "201603") Section <- c(rep("A",5),rep("B",5)) df <- data.frame(cbind(Week, Section)) Section <- c("A", "B") Start <- c("201401","201551") End <- c("201404","201603") Weeks_Filter <- data.frame(cbind(Section, Start, End))