I have a dataframe with let’s say N+2 columns. The first is just dates (mainly used for plotting later on), the second is a variable whose response to the remaining N columns I would like to compute. I’m thinking there must be something like
df = data.frame(y = 1:10, x1 = runif(10), x2 = rnorm(10))
fit = lm(y~df[,2:3],data=df)
This doesn’t work. I’ve also tried and failed with
fit = lm(y~sapply(colnames(df)[2:3],as.name),data=df)
Any thoughts?
Using the formula notation
y ~ .specifies that you want to regress y on all of the other variables in the dataset.