Reputation: 1
I am writing an extension for K-means in SPSS (in R language). I have successfully written the code to calculte K-means and now I want to save a number of a cluser as a new variable, but I don't know how to do that. I have it saved as kmeans_cluster[1], but how do I save it in SPSS as a new variable?
Code:
BEGIN PROGRAM R.
no_clust <- as.numeric(%%no_clust%%)
no_rep<- as.numeric(%%no_rep%%)
max_iterations <- as.numeric(%%max_iterations%%)
casedata <- spssdata.GetDataFromSPSS()
stand <- %%item_14%%
varList <- "%%item_11%%"
varList <- strsplit(varList, split = ",")[[1]]
kmeans_results <- NULL
if (stand ==TRUE) {
casedata_z <- scale(na.omit(casedata[, c(varList)]))
kmeans_results <- kmeans(x = casedata_z, centers = no_clust, nstart=no_rep, iter.max=max_iterations)
} else {
kmeans_results<- kmeans(x = na.omit(casedata[, c(varList)]), centers = no_clust, nstart=no_rep, iter.max=max_iterations)
}
kmeans_clusters <- kmeans_results[1]
END PROGRAM.
Upvotes: 0
Views: 26