Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

Say I have a linear model in R. Using the model object, how can I see the number of observations used to train that model?

Let say, for instance:

library(ISLR)

lm.fit <- lm(mpg ~ acceleration + weight + horsepower + displacement, data = Auto)

lm.fit

How to see the number of observations used to train the model lm.fit?

1 Answer

0 votes
by (107k points)

For that, you can check the number of fitted values.

length(lm.fit$fitted.values)

# [1] 392

Check:

dim(Auto)

# [1] 392   9

If you are a beginner and want to know more about R then do refer to the following R programming tutorial.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...