I am trying to build a vector of strings as an input for model testing (it eventually goes into the lmer function). I Have to change around the columns a lot for different tests, so doing this at the start by declaring them in one place would really speed up the process.
The vector (of strings) is made up of column headings (from the data). There are currently two fixed starting points, and then I would like to iterate through the available column options without repetition and where order is not important.
Example input:
first_col <- "SpA"
secondFixedcol <- "SpecB"
other_cols <- c("C", "D", "E", "F") #This can have any number of parameters
Example output for model text:
modelsText <- c('SpecB',
'SpA + SpecB',
'SpA + SpecB + C',
'SpA + SpecB + D',
'SpA + SpecB + E',
'SpA + SpecB + F',
'SpA + SpecB',
'SpA + SpecB + C + D',
'SpA + SpecB + C + E',
'SpA + SpecB + C + F',
'SpA + SpecB + C + D + E',
'SpA + SpecB + C + D + F',
'SpA + SpecB + C + D + E + F')
My mind is trying to tell me to build some sort of frankenstein For Loop using the Paste function (that is still beyond me at this stage), but there must be something more elegant using vectorisation?
My other idea is to use combinations(4, 3, other_cols, repeats.allowed = FALSE)
and then use a nested For Loop to move through that?