我有这样的数据:
structure(list(group = c("A", "A", "A", "A", "B", "B"), date = structure(c(1262304000,
1267401600, 1288569600, 1293840000, 1328054400, 1333238400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), freq = c(5, 1, 20, 6, 2, 8)), .Names = c("group",
"date", "freq"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-6L))
> df
# A tibble: 6 x 3
group date freq
<chr> <dttm> <dbl>
1 A 2010-01-01 5
2 A 2010-03-01 1
3 A 2010-11-01 20
4 A 2011-01-01 6
5 B 2012-02-01 2
6 B 2012-04-01 8
我想按组扩展日期列,以得到以下结果:
structure(list(group = c("A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "B", "B", "B"), date = structure(c(1262304000,
1264982400, 1267401600, 1270080000, 1272672000, 1275350400, 1277942400,
1280620800, 1283299200, 1285891200, 1288569600, 1291161600, 1293840000,
1328054400, 1330560000, 1333238400), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), freq = c(5, 0, 1, 0, 0, 0, 0, 0, 0, 0, 20,
0, 6, 2, 0, 8)), .Names = c("group", "date", "freq"), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -16L))
> df_out
# A tibble: 16 x 3
group date freq
<chr> <dttm> <dbl>
1 A 2010-01-01 5
2 A 2010-02-01 0
3 A 2010-03-01 1
4 A 2010-04-01 0
5 A 2010-05-01 0
6 A 2010-06-01 0
7 A 2010-07-01 0
8 A 2010-08-01 0
9 A 2010-09-01 0
10 A 2010-10-01 0
11 A 2010-11-01 20
12 A 2010-12-01 0
13 A 2011-01-01 6
14 B 2012-02-01 2
15 B 2012-03-01 0
16 B 2012-04-01 8
增量应该是每个月,频率应该是0。我如何在dplyr管道内实现这个?