Is your shapefile multipart? If so the spatial classes in R do not support multipart shapefiles at this time. If you get stuck, you can forgo using ArcGIS and directly use R for this analysis. Here is a example in R that runs an optimized K-medoid clustering. You can use readOGR in the rgdal library or readPointsShape in the maptools library to read shapefiles into a R spatial class. Your dataframe can be accessed using the @data slot notation.
require(cluster)
require(rgdal)
require(sp)
# READ SHAPEFILE (rgdal example)
shape <- readOGR(dsn="C:/ANALYSIS", layer="shape_points")
# OPTIMIZED K-MEDOIDS FUNCTION
OptK <- function(x, nk=10, plot=TRUE, cluster=TRUE, clara=FALSE, ...) {
if (!require(cluster)) stop("cluster PACKAGE MISSING")
asw <- numeric(nk)
for (k in 2:nk) {
if(clara==TRUE) { asw <- clara(x, k, ...)$silinfo$avg.width }
if(clara==FALSE) { asw <- pam(x, k, ...)$silinfo$avg.width }
k.best <- which.max(asw)
}
print(paste("OPTIMAL-K", k.best, sep=": "))
if(plot==TRUE) {
plot(1:nk, asw, type="s", main="Clustering Optimization using K-Mediods",
xlab="K (number of clusters)", ylab = "mean silhouette width")
axis(1, k.best, paste("best",k.best,sep="\n"), col="red",
col.axis="red")
}
if(cluster==TRUE) {
if(clara==TRUE) { return(clara(x, k.best, ...)) }
if(clara==FALSE) { return(pam(x, k.best, ...)) }
}
}
# CLUSTER DATA AND PLOT FIT
point.clust <- OptK(shape@data[,2:5], 20, plot=TRUE, cluster=TRUE, clara=TRUE, sample=500)
plot(silhouette(point.clust), col = c("red", "green"), main="Cluster Silhouette's")
plot(point.clust, which.plots=1, main="K-MEDIOD FIT")
# EXTRACT MEDIOD CLUSTER BREAKS
point.clust$medoids
# JOIN CLUSTERS TO DATA
shape@data <- data.frame(shape@data, k=point.clust$clustering)
# WRITE RESULTS SHAPEFILE (maptools example)
writePointsShape(shape, "C:/ANALYSIS/cluster_results")