Description
In the BostonHousing.csv.gz file, there is a column "CAT. MEDV". The code references this value as "CAT.MEDV" but R coerces the whitespace when using read.csv() to be another '.', resulting in the column representing as "CAT..MEDV" to R. This causes downstream errors when using the aggregation method and attempting to reference this misnomer.
Problem can be resolved by either changing the CSV file's column name to be "CAT.MEDV" by deleting the whitespace, or by altering the source code for Figure 3.1 to be "CAT..MEDV"
#Non-functional Code
CAT.MEDV.per.CHAS <- aggregate(housing.df$CAT.MEDV,
by=list(housing.df$CHAS),
FUN=mean)
names(CAT.MEDV.per.CHAS) <- c("CHAS", "MeanCATMEDV")
CAT.MEDV.per.CHAS$CHAS <- factor(CAT.MEDV.per.CHAS$CHAS)
#Functional Code
CAT.MEDV.per.CHAS <- aggregate(housing.df$CAT..MEDV,
by=list(housing.df$CHAS),
FUN=mean)
names(CAT.MEDV.per.CHAS) <- c("CHAS", "MeanCATMEDV")
CAT.MEDV.per.CHAS$CHAS <- factor(CAT.MEDV.per.CHAS$CHAS)
Activity