dates=data.frame(table(df13$date_of_admission))
newdf=data.frame(Var1=seq(as.Date("2018/01/01"),as.Date("2021/01/31"),by="day"))
f1=numeric(length(newdf$Var1))
for (i in 1:length(newdf$Var1)) {
for (j in 1:length(dates$Var1)) {
if(as.Date(newdf$Var1[i])==as.Date(dates$Var1[j])){
f1[i]=dates$Freq[j]
}
}
}
newdf$Freq=f1
Var1 denotes date. In dates data frame, It consists dates and corresponding frequencies. I created newdf with specific date range. Now I want to add frequencies in dates data frame to newdf. I used above for loops to do that job. Since I need to put zero for frequency in newdf which is not in dates data frame, I used those for loops. This code works well but take some time to run. So I need a method do to this without for loops.