我有一个看起来像
的数据集(“dl”)ID start_dt end_dt location
1 2015-12-31 2016-01-04 dallas
2 2015-12-24 2016-01-01 kansas
3 2016-01-01 2016-01-05 kansas
1 2016-01-04 2016-01-18 dallas
5 2016-01-10 2016-01-17 dallas
6 2016-01-09 2016-01-17 houston
7 2016-01-11 2016-01-18 dallas
我的目标是将数据集(这是300,000多个观测值的子集)提供给下面的数据集(我们称之为“ds”)
ID Date location
1 2015-12-31 dallas
1 2016-01-01 dallas
1 2016-01-02 dallas
1 2016-01-03 dallas
1 2016-01-04 dallas
2 2015-12-24 kansas
2 2015-12-25 kansas
2 2015-12-26 kansas
2 2015-12-27 kansas
2 2015-12-28 kansas
2 2015-12-29 kansas
2 2015-12-30 kansas
2 2015-12-31 kansas
2 2016-01-01 kansas
3 2016-01-01 kansas
3 2016-01-02 kansas
3 2016-01-03 kansas
3 2016-01-04 kansas
3 2016-01-05 kansas
1 2016-01-04 kansas
1 2016-01-05 kansas
1 2016-01-06 kansas
1 2016-01-07 kansas
1 2016-01-08 kansas
1 2016-01-09 kansas
1 2016-01-10 kansas
1 2016-01-11 kansas
1 2016-01-12 kansas
1 2016-01-13 kansas
1 2016-01-14 kansas
1 2016-01-15 kansas
1 2016-01-16 kansas
1 2016-01-17 kansas
1 2016-01-18 kansas
5 2016-01-10 dallas
5 2016-01-11 dallas
5 2016-01-12 dallas
5 2016-01-13 dallas
5 2016-01-14 dallas
5 2016-01-15 dallas
5 2016-01-16 dallas
5 2016-01-17 dallas
6 2016-01-09 houston
6 2016-01-10 houston
6 2016-01-11 houston
6 2016-01-12 houston
6 2016-01-13 houston
6 2016-01-14 houston
6 2016-01-15 houston
6 2016-01-16 houston
6 2016-01-17 houston
7 2016-01-11 dallas
7 2016-01-12 dallas
7 2016-01-13 dallas
7 2016-01-14 dallas
7 2016-01-15 dallas
7 2016-01-16 dallas
7 2016-01-17 dallas
7 2016-01-18 dallas
最终,我的目标是通过以下代码运行它:
require(dplyr)
df <- ds %>%
group_by(Date, location) %>%
summarise(Counts = n())
plot(df$Date, df$Counts)
但我无法从数据集 dl 转到 ds 。我尝试过使用
ds <- dl[,.(Date = seq(start_dt, end_dt, by="1 day")), by=list(ID, location)]
但是我得到了
Error in seq.Date(start_dt, end_dt, by = "1 day") :
'from' must be of length 1
在线查看,我只看到了from
和/或to
位置是单个值而非动态值的示例。是否有可以进行此扩展的包或代码?任何帮助都会令人难以置信!