Problem
I'm working on data with several variables including a "date" variable. The problem is that i need to have all dates for all couple of variable. Here is an example of my dataframe:
df <- data.frame(c("a","a","c","c","c"),c(15,16,0,18,95),c(0,16,0,18,95),c(2017.01,2017.02,2017.01,2017.02,2017.03))
colnames(df) <- c("PL","CDE","LIV","date")
I would like to create the row with date 2017.03 as date for the PL a and set the values CDE and LIV to 0.
I gave you here a simplified example but i have multiple values for PL and multiple missing date. I mean, one PL will have 2017.01 and 201.05 missing but another one will hahe 2017.01, 2017.02, 2017.03.
What i tried
I tried to create an array "sem" of date from 2013.01 to 2013.53 and 2014.01 to 2014.53, ... 2017.01 to 2017.47 and then i created a for loop over the PL variable andin the array "sem" i keep only the date that i don't have for the variable "PL" and i just do a cbind of the array "sem" and the variable "PL" so it duplicates it itself and then i create the variables "CDE" and "LIV" that i set to 0 and finnaly i do an rbind
But this solution takes too long i have over 38 000 variable "PL"