I am trying to calibrate a model and I need to vary some parameters to see how the output behaves. To do that I would like to create a data frame where each row is one set of parameters.
An example data set:
pars <- data.frame(a=3, b=4, c=5)
Vary the parameter a
:
dfa <- data.frame(a = 1:6)
Then try to join it in a new data frame:
bind_cols(dfa, pars[rep(seq_len(nrow(pars)), each=length(a)),])
The same process goes for b
.
dfb <- data.frame(b = 3:6)
dfb <-
bind_cols(dfb, pars[rep(seq_len(nrow(pars)), each=length(dfb$b)),]) %>%
select(-c(b1))
bind_rows(dfa,dfb)
This is not a very effective way for a model of around 30 parameters. I am guessing this should be put into a loop of some sort. I am probably not the first person trying to do this, so I would appreciate some help if someone has already done this. Some answers to similar problems are this and I have used this as a part of my attempt. This comment is also interesting because I have a varying number of rows to repeat:
n.times <- c(2,4) ; df[rep(seq_len(nrow(df)), n.times),]
Any help on this is appreciated.