0

I have a dataframe with 2 variables and multiple Product_Ids. For some Ids, some dates are missing.

library(dplyr)

df <- data.frame(Product_Id = rep(1:100, each = 50), 
                 Date = seq(from = as.Date("2008/1/1"), to = as.Date("2018/2/1") , by = "month"), 
                 Sales = rnorm(100, mean = 50, sd= 20))
df <- df[-c(1,4,67,78,251:256, 301:312, 2551:2562, 2651:2662, 2751:2762), ]
x <- count(df, vars = Product_Id)
View(df)

Is there anyway to create a dataframe which contains all the Dates in the right sequence along with the Product_Id and empty cells corresponding to Sales?

user10579790
  • 333
  • 1
  • 10

0 Answers0