I'm having trouble trying to put variables, which are in list, into a glm-function. My dataframe has lots of variables, so it would be too much effort to type the independent variables one by one into glm. Lets say my dataframe is
df <- data.frame(
id = c(1,2,3,4,5),
`sitting position` = c("A","B","A","A","B"),
`variable one` = c("left", "left", "right", "right", "left"),
`variable two` = c(50, 30, 45, 80, 57),
`variable three` = c("m","w","w","m","m"),
check.names = FALSE)
and my list of columns which I want to use in a glm-function looks like this
columns <- dput(colnames(df))[-c(1:2)]
columns
[1] "variable one" "variable two" "variable three"
Now I want to put this list directly into a glm- function, something like
glm(`sitting position` ~ columns, data = df, familiy = binomial).
instead of
glm(`sitting position` ~ `variable one` + `variable two` + `variable three`, data = df, family = binomial())
I am aware that I can't work just by adding the list, but I also can't find a solution to fix this problem.