答案 0 :(得分:0)
合并data_frame
,其中包含data_frame
中日期的最小值和最长值之间的所有日期。
# data_frame with data that does not contain weekends
df_foo = data_frame(
date = seq.Date(from = as.Date("2016-01-01"),
to = as.Date("2016-06-01"),
by = "day"),
y = rnorm(length(date))
) %>%
filter(!chron::is.weekend(date))
df_foo %>%
left_join(
# create a data_frame with all the dates in the range
data_frame(date = seq.Date(from = min(df_foo$date), to = max(df_foo$date), by = "day")),
# join with the date
.,
by = "date"
) %>%
# convert all the NA to zero
mutate(y = ifelse(is.na(y), 0, y))