I have the following question : is it possible to fill some missing rows in a database ?
Please find below an exemple of what I attempt to do. I have a database with some sellers and buyers and monthly transactions
library(data.table)
set.seed(1)
Data <- data.frame(
Month = c(1,5,3,4,5,3,4,5,6),
Code_ID_Buy = c("100D","100D","102D","102D","102D","100D","100D","100D","100D"),
Code_ID_Sell = c("98C","98C","99C","99C","99C","25A","25A","25A","25A"),
Contract_Size = c(100,20,120,300,120,30,25,150,250)
)
View(Data)
The issue is that some months are missing, hence I would need to insert one row each time there is a missing row (an after the last occurence) with the ID of the buyer the seller and a contract value of 0, so that the data looks like :
Data <- data.frame(
Month = c(1,2,3,4,5,6,3,4,5,6,3,4,5,6,7),
Code_ID_Buy = c("100D","100D","100D","100D","100D","100D","102D","102D","102D","102D","100D","100D","100D","100D","100D"),
Code_ID_Sell = c("98C","98C","98C","98C","98C","98C","99C","99C","99C","99C","25A","25A","25A","25A","25A"),
Contract_Size = c(100,0,0,0,20,0,120,300,120,0,30,25,150,250,0)
)
View(Data)
Thank you in advance,
Kind regards,
question from:
https://stackoverflow.com/questions/65939631/rstudio-filling-missing-rows