Obtaining subsets for a fixed number of predictors

I am doing homework in R for my stats class and I was given these codes to put into R.

library(leaps)
subset.output = regsubsets(y~x1+x2+...+x_p, data = name of data set, nbest = 1)

so with my variables I did the first step and then I entered this code into R

subset.output=regsubsets(SuggestedRetailPrice~HorsePower+DealerCost+HighwayMPG+Weight+WheelBase,data=car.data,nbest=1)

When I put that into R, this error pops up

Error in as.data.frame.default(data) :
cannot coerce class ‘"lm"’ to a data.frame

I have no idea what I'm doing wrong and my teacher isn't helping me, can someone please help me?

Is car.data a data frame? What is the result of

class(car.data)

I ended up figuring out what the problem was, thank you for your help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.