Natalie Beth Garces
Natalie Beth Garces

Reputation: 1

LM not working (Error in terms.formula(formula, data = data) invalid model formula in ExtractVars

Trying to run the function

CatFit1<-lm(PRICE~BATHS+BEDS+ 'SQUARE FEET'+CatLotData2$LotCat+ 
            'YEAR BUILT'+CatLotData2$NeighCat, data=CatLotData2)

but getting this error message:

Error in terms.formula(formula, data = data) : 
  invalid model formula in ExtractVars

Anyone have an idea of the problem?

Upvotes: 0

Views: 7566

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269644

If there are spaces in the variable names surround them with backticks, not single quotes. For example,

PRICE ~ BATHS + BEDS + `SQUARE FEET`

The other possibility is to change the names so that they don't have spaces in them in the first place.

Upvotes: 2

Related Questions