Appendix D. R Code for Supporting Market Segment Business Case Calculations

The code for supporting market segment business case calculations in Chapter 5, Data Mining with Cluster Analysis, is as follows:

# create dataframe with columns for distances compare <- cbind(clus, dist2 = rep(0, dim(clus)[1]), dist3 = rep(0, dim(clus)[1])) # ------- # functions to find distance based on Spherical Law of Cosines distance2 <- function(lat, long, clus_id) { acos(sin(lat * pi / 180) * sin(two$centers[clus_id, 1] * pi / 180) + cos(lat * pi / 180) * cos(two$centers[clus_id, 1] * pi / 180) * cos(two$centers[clus_id, 2] * pi / 180 - long * pi / 180)) * 6371 #in km } distance3 <- function(lat, long, clus_id) { acos(sin(lat * pi / 180)*sin(three$centers[clus_id, ...

Get Introduction to R for Business Intelligence now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.