Here is a reproducible example of what I want to achieve. Basically I have a datefrom column, dateto column and some value columns and I want to create a time series for each day of the intervals defined with datefrom and dateto. I previously used rowwise, but it is quite slow for larger datasets. Is there a more performant way to do this?
library(tidyverse)
library(lubridate)
# getting some data ready
df <- tibble(datefrom = c("2019-01-01", "2019-01-01"),
dateto = c("2019-01-02", "2019-01-04"),
value = 5) %>%
mutate_if(is.character, ymd)
# preparing the time series
df %>%
rowwise() %>%
mutate(Date = list(seq.Date(datefrom, dateto, by = "days")), datefrom = NULL, dateto = NULL) %>%
unnest()
# how to use pmap
df <- tibble(od = 1:3,
do = 4:6)
df %>%
mutate(seq = pmap(.l = list(od, do), ~ seq(.x, .y)), od = NULL, do = NULL) %>%
unnest(seq)