我正在使用如下所示的数据框:
date<-c("2012-02-01", "2012-02-01", "2012-02-03", "2012-02-04", "2012-02-04", "2012-02-05", "2012-02-09", "2012-02-12", "2012-02-12")
var<-c("a","b","c","d","e","f","g","h","i")
df1<-data.frame(date,var)
我想创建第二个数据框,将我每天的观察次数制成表格。在该数据框中,未提及的日期将为零……结果如下:
date<-c("2012-02-01","2012-02-02","2012-02-03","2012-02-04","2012-02-05","2012-02-06","2012-02-07","2012-02-08","2012-02-09","2012-02-10","2012-02-11","2012-02-12")
num<-c(2,0,1,2,1,0,0,0,1,0,0,2)
df2<-data.frame(date,num)
我已经用聚合函数尝试了很多东西,但不知道如何在没有观察到的情况下包含日期(零)。