How to run a linear model in R with a specific data range?

I am running a linear model on my dataset whose size is 2 columns and 100 rows. How can I run a model for a specific data range, for example, from line 30 to line 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.

+4
source share
1 answer

For example,

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

Or using the parameter subset:

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

All Articles