Enrique Ruix
10 of April 2016
This app is part of the Developing Data Products Peer Assignment within the Coursera Data Science Specialisation. This app aims to be used as a tool for exploring the mtcars dataset in R. You could use the app for:
You will be asked to select two variables as well as the number of clusters to create:
Variable 1 vs. Variable 2 plot
The next code performs a hieralchical clustering for hp and mpg with 3 different groups and calculate the average hp and mpg for the different clusters. The output will be shown in the next slide.
clusters<-kmeans(mtcars[, c("hp", "mpg")], 3)
data<-cbind(data.frame(Group=c(clusters$cluster)),mtcars[,c(1,2)])
avg_var1<-with(data,aggregate(mtcars[,"hp"],by=list(Group),FUN=mean))
avg_var2<-with(data,aggregate(mtcars[,"mpg"],by=list(Group),FUN=mean))
names(avg_var1) <- c("Group", paste("Average", "hp"))
names(avg_var2) <- c("Group", paste("Average", "mpg"))
data <- merge(avg_var1, avg_var2)
.
Those two outputs will help you to:
.
.
Group Average hp Average mpg
1 1 93.52941 24.22353
2 2 263.80000 14.62000
3 3 178.50000 15.80000
Find below useful links to find the app, code and this presentation: