crime <- doBy::crimeRate
rownames(crime) <- crime$state
crime$state <- NULL
o <- order(apply(scale(crime), 1, sum))
dat <- crime[o,]
head(dat)
tail(dat)
matplot(scale(dat), type="l")
pc1 <- prcomp(dat, scale. = TRUE)
summary(pc1)
rec2 <- recover_pca_data(pc1, 2)
pairs(rec2)
par(mfrow=c(1,2))
matplot(scale(dat), type="l")
matplot(scale(rec2), type="l")
j <- merge(dat, rec2, by=0)
pairs(j[,-1])
Run the code above in your browser using DataLab