简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM