Clean Errors in Data
Any large, complex data set collected over a long period of time might contain some errors. Check for
errors in the housing data. Dates in the data are a good place to start. First compare YearBuilt to
YearRemod_Add.
checkRows = housing.YearBuilt > housing.YearRemod_Add;
housing(checkRows,:)
ans=1×24 table
PID
MSSubClass
LotFrontage
LotArea
Neighborhood
____________
_______________________________
___________
_______
____________
"0907194160"
1-STORY 1946 & NEWER ALL STYLES
65
10739
CollgCr
It is not possible for remodeling to have been done in 2001 if the house itself was built in 2002. If you
assume that the YearBuilt value is known to be the error (an assumption that needs to be
confirmed), you can use dot notation to assign 2001 as the year in which this house was built.
housing.YearBuilt(checkRows) = 2001;
As another check, compare the new LastSoldDate variable to YearBuilt.
checkRows = housing.YearBuilt > year(housing.LastSoldDate);
housing(checkRows,:)
ans=2×24 table
PID
MSSubClass
LotFrontage
LotArea
Neighborhood
9 Tables
9-74
Any large, complex data set collected over a long period of time might contain some errors. Check for
errors in the housing data. Dates in the data are a good place to start. First compare YearBuilt to
YearRemod_Add.
checkRows = housing.YearBuilt > housing.YearRemod_Add;
housing(checkRows,:)
ans=1×24 table
PID
MSSubClass
LotFrontage
LotArea
Neighborhood
____________
_______________________________
___________
_______
____________
"0907194160"
1-STORY 1946 & NEWER ALL STYLES
65
10739
CollgCr
It is not possible for remodeling to have been done in 2001 if the house itself was built in 2002. If you
assume that the YearBuilt value is known to be the error (an assumption that needs to be
confirmed), you can use dot notation to assign 2001 as the year in which this house was built.
housing.YearBuilt(checkRows) = 2001;
As another check, compare the new LastSoldDate variable to YearBuilt.
checkRows = housing.YearBuilt > year(housing.LastSoldDate);
housing(checkRows,:)
ans=2×24 table
PID
MSSubClass
LotFrontage
LotArea
Neighborhood
9 Tables
9-74
