I have a dataframe like below.I want add rows for each name with year and missing week of the year with a total value of 0.
Name Year Week Total
John 2021 1 3
John 2021 2 2
John 2021 5 1
John 2021 10 2
Mary 2020 3 1
Mary 2021 5 2
Expected result
John 2021 1 3
John 2021 2 2
John 2021 3 0
John 2021 4 0
John 2021 5 1
John 2021 6 0
.
.
.
John 2021 53 0
This is what I am trying to do
data1<-data %>%
complete(Week = seq(min(Week), max(Week), by = 'week')) %>%
mutate_each(funs(ifelse(is.na(.),0,.)))
padrcran.r-project.org/web/packages/padr/vignettes/padr.html