# NOT RUN {
# Combine Titanic passenger attributes into a single category
tab <- t(as.data.frame(apply(Titanic, 4:1, FUN=sum)))
# Remove rows with all zeros
tab <- tab[apply(tab, 1, sum) > 0, ]
# Perform clustering on contingency table
grc <- greenclust(tab)
# Plot r-squared and p-values for each potential cut point
greenplot(grc)
# Get clusters at suggested cut point
clusters <- greencut(grc)
# Plot dendrogram with clusters marked
plot(grc)
rect.hclust(grc, max(clusters))
# }
Run the code above in your browser using DataLab