I am trying to split the values based on dates in r. Here is a dummy of my data:
df = data.frame(ID= c('A','B','C'),
year = c('2019','2019','2020'),
start= c('201850','201940','201850'),
end= c('201903','202002','202110'),
value = c(45,14,117))
ID year start end value
A 2019 201850 201903 45
B 2019 201940 202002 14
C 2020 201850 202110 117
What I need in the output is the value divided on year-week level. Only for years after 2019 with the assumptrion that value is distributed evenly over weeks. For instance the first row of the dummy data (A) will be only 3 weeks in 2019. Since the value for A is for 5 weeks(201850 to 201903), for 3 weeks in 2019 it will be equal to 27().
Desired output is:
ID year start end value
A 2019 201901 201903 27
B 2019 201940 201952 12
B 2020 202001 202002 2
C 2019 201901 201952 52
C 2020 202001 202053 53
C 2021 202101 202110 10