I want to iterate over a list of strings and append these to my formula one by one and adding the extra name after each iteration. For example, my code produces the following output:
require(faraway)
col_names <- names(teengamb)[-5]
form <-0
for(i in 1:length(col_names)){
form[i]=list(formula(paste('gamble ~', paste(col_names[i], collapse='+'))))
}
[[1]]
gamble ~ sex
[[2]]
gamble ~ status
[[3]]
gamble ~ income
[[4]]
gamble ~ verbal
Expected output:
[[1]]
gamble ~ sex
[[2]]
gamble ~ sex+status
[[3]]
gamble ~ sex+status+income
[[4]]
gamble ~ sex+status+income+verbal