Let's say I have two vectors (in the case below, they're cycles
and thedates
) that I want to combine every pair combination between them in a list. The code below gives me the output inlist
that I want but I don't think it's very efficient. I was trying different things with outer
but I couldn't make it work.
library(lubridate)
library(data.table)
cycles <- c(1,2,10*1:24)
thedates <- seq(ymd('2016-08-13',tz='GMT'), ymd('2019-08-13',tz='GMT'),by='day')
inputs <- matrix(nrow=length(thedates)*length(cycles),ncol=2)
inputs[,1] <- rep(thedates,each=length(cycles))
inputs[,2] <- rep(cycles,length(thedates))
inlist <- lapply(1:nrow(inputs), function(x) c(inputs[x,1], inputs[x,2]))