Skip to content

Instantly share code, notes, and snippets.

@sureshgorakala
Created February 27, 2016 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sureshgorakala/6e335dec0606f3c519df to your computer and use it in GitHub Desktop.
Save sureshgorakala/6e335dec0606f3c519df to your computer and use it in GitHub Desktop.
Data Science using R
library(pca)
data("crimtab") #load data
head(crimtab) #show sample data
dim(crimtab) #check dimensions
str(crimtab) #show structure of the data
sum(crimtab)
colnames(crimtab)
apply(crimtab,2,var) #check the variance accross the variables
pca =prcomp(crimtab) #applying principal component analysis on crimtab data
par(mar = rep(2, 4)) #plot to show variable importance
plot(pca)
'below code changes the directions of the biplot, if we donot include
the below two lines the plot will be mirror image to the below one.'
pca$rotation=-pca$rotation
pca$x=-pca$x
biplot (pca , scale =0) #plot pca components using biplot in r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment