How to run linear model in R with certain data range?

南楼画角 提交于 2019-12-01 05:57:41

问题


I run a linear model on my dataset which has the dimension of 2 columns and 100 rows. How could I run the model for a certain data range e.g from row 30 to row 80?

set.seed(123)     # allow reproducible random numbers
A <- data.frame(x=rnorm(100), y=runif(100))# 2 columns with 100 rows of data
fit.lm <- lm(A$x~A$y) #fit 100 data
summary(fit.lm)# summary 100 data

Thanks in advance.


回答1:


For example ,

lm(x~y,data = A[30:80,])

Or using subset parameter:

lm(x~y,data=A,subset=30:80)


来源:https://stackoverflow.com/questions/20214504/how-to-run-linear-model-in-r-with-certain-data-range

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