我想这是一个相当容易的问题:我想计算一些日期在时间线上出现的频率。向量allDates包含我想要绘制的所有日期。
allDates <- structure(c(16193, 16194, 16195, 16196, 16197, 16198, 16199,
16200, 16201, 16202, 16203, 16204, 16207, 16208, 16209, 16210,
16211, 16212, 16214, 16215, 16216, 16217, 16218, 16219, 16221,
16222, 16223, 16224, 16225, 16226, 16235, 16236, 16237, 16238,
16268, 16270, 16271, 16272, 16273), class = "Date")
应计算矢量dataSubset的频率。
dataSubset <- structure(c(16193, 16193, 16193, 16194, 16195, 16195, 16195,
16195, 16195, 16195, 16195, 16196, 16196, 16196, 16196, 16196,
16196, 16197, 16197, 16197, 16197, 16198, 16200, 16200, 16200,
16200, 16200, 16200, 16201, 16202, 16202, 16202, 16202, 16202,
16202, 16203, 16203, 16203, 16203, 16207, 16207, 16207, 16208,
16208, 16208, 16208, 16208, 16208, 16208, 16208, 16208, 16209,
16209, 16209, 16209, 16209, 16209, 16210, 16210, 16210, 16211,
16211, 16211, 16211, 16211, 16211, 16211, 16211, 16211, 16211,
16211, 16211, 16211, 16211, 16211, 16211, 16212, 16212, 16214,
16214, 16214, 16214, 16214, 16215, 16215, 16215, 16215, 16216,
16216, 16216, 16216, 16216, 16216, 16217, 16217, 16217, 16217,
16217, 16217, 16217, 16217, 16218, 16218, 16218, 16218, 16218,
16218, 16218, 16218, 16218, 16218, 16218, 16218, 16219, 16219,
16219, 16219, 16221, 16221, 16222, 16223, 16223, 16223, 16223,
16223, 16223, 16223, 16223, 16224, 16224, 16224, 16225, 16225,
16225, 16226, 16235, 16235, 16235, 16235, 16235, 16236, 16236,
16236, 16236, 16236, 16236, 16236, 16236, 16236, 16236, 16237,
16237, 16237, 16237, 16237, 16237, 16237, 16238, 16238, 16238,
16238, 16238, 16238, 16238, 16238, 16238, 16238, 16238, 16238,
16270, 16270, 16270, 16271, 16271, 16271, 16271, 16272, 16273,
16273, 16273, 16273, 16273), class = "Date")
如果我只是在数据子集上使用表函数,我会得到数据子集中所有日期的频率。
table(datasubset)
但是,我还想在数据子集中包含没有事件发生的日期。换句话说,我还想包括allDates中的日期的零频率,但不包括计算频率的dataSubset向量。