Skip to content
Prev 379616 / 398503 Next

Iterating dates over multiple ids

Hi all, 

I want to create a df that repeats the dates over ids. Previously I tried expand.grid but this created every possible iteration of dates and ids, when all I want is the start and end dates repeated for each month. In other words 01/03/19 with an end date of 28/02/19 would be unsuitable. I have also been told that rbind may be unsuitable when the data is scaled up to tens of thousands of rows. I would appreciate any suggestions. 

library(lubridate)
#get list of month dates for last 6 months
end_months <- ymd("2018-11-01")+ months(0:6)-days(1)
start_months <- ymd("2018-10-01")+ months(0:6)

#list of view ids required to make api call (pseudonymised) viewId <- c(26494958, 477448251, 47843527, 96382507, 537821552, 67482819)
All the best

Graeme R Davidson PhD

Data and Insight Analyst