'Warning message: 'newdata' had 20 rows but variables found have 1000 rows

#This is my model

linearMod <- lm( Housing_Training$SalePrice ~ Housing_Training$MSSubClass + Housing_Training$LotFrontage + Housing_Training$LotArea + Housing_Training$OverallQual + 
                   Housing_Training$OverallCond + Housing_Training$YearBuilt + Housing_Training$YearRemodAdd + Housing_Training$MasVnrArea + Housing_Training$TotalBsmtSF +
                   Housing_Training$GrLivArea + Housing_Training$FullBath + Housing_Training$HalfBath + Housing_Training$BedroomAbvGr +Housing_Training$KitchenAbvGr + Housing_Training$TotRmsAbvGrd + 
                   Housing_Training$Fireplaces + Housing_Training$GarageYrBlt + Housing_Training$GarageCars + Housing_Training$GarageArea + Housing_Training$WoodDeckSF + Housing_Training$OpenPorchSF +
                   Housing_Training$MoSold + Housing_Training$YrSold, data=Housing_Training)




#this is my test data that i want to use in the model:

Housing_Testing_20x <- Housing_Testing[complete.cases(Housing_Testing), ]
Housing_Testing_20<-data.frame(Housing_Testing_20x[1:20,])

predict(linearMod,newdata = Housing_Testing_20)

Basically, my Housing_Testing LM model contains 1000 rows (comparing sale price column to all other columns (size, rooms, etc.)

Then I have a Housing_testing dataset, I need to take out all of rows that have NA, and then take the first 20 rows and use the model to predict a housing price.

However, when I try to run the linearmodel with the Housing _testing_20 dataset it's giving me an error (after showing me 1000 rows); my response should be 20 rows of Housing Sale price predictions



Solution 1:[1]

FIgured out the column heading were wrong when i created the lm

the one below worked:

linearMod <- lm(SalePrice ~ MSSubClass+LotFrontage+LotArea+OverallQual+ OverallCond+YearBuilt+YearRemodAdd+MasVnrArea+ TotalBsmtSF+GrLivArea+FullBath+ HalfBath+KitchenAbvGr+  TotRmsAbvGrd+Fireplaces+   GarageYrBlt+GarageCars+  GarageArea+   WoodDeckSF+  OpenPorchSF+  MoSold+  YrSold, data = Housing_Training)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TylerH