I want to write a function which will take three arguments:
df
a data.frame
Y
a character with the name of one of the df
columns
X
a character vector of names of the df
columns.
The function should output the glm
of Y
on X
.
For example fun(df, Y = "Price", X = c("sqft", "rooms"))
should output the same object as
glm(Price ~ sqft + rooms, data = df)
.
What's the best way to do this?