Shortcut using lm() in R for formula

北慕城南 提交于 2019-11-28 01:58:26

Try lm(y ~ ., data) where . means "every other column in data besides y.

m <- matrix(rnorm(100), ncol =5)
m <- as.data.frame(m)
names(m) <- paste("m", 1:5, sep="")
lm(m1 ~., data=m)

You can reassign m to include only the columns you as the predictors

m <- m[ ,2:4]
lm(m1 ~ ., data=m)

There is another one shortcut for the cases when a dependent variable is in the first column:

data <- data.frame(y = rnorm(10), x1 = rnorm(10), x2 = rnorm(10))
lm(data)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!