stats package offers the
prcomp function to perform PCA. This recipe shows you how to perform PCA using these capabilities.
If you have not already done so, download the data files for this chapter and ensure that the
BostonHousing.csv file is in your R working directory. We want to predict
MEDV based on the remaining 13 predictor variables. We will use PCA to reduce the dimensionality.
To reduce dimensionality with PCA, follow the steps:
> bh <- read.csv("BostonHousing.csv")